Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
2012 / MISRA / EW_MisraCReference.pdf
Скачиваний:
129
Добавлен:
10.02.2015
Размер:
650.9 Кб
Скачать

Initialization

The linker will generate an error, indicating a violation of this rule, if the same structure or enumeration tag is used in several different translation units.

Initialization

The rules in this section are concerned with the initialization of variables.

Rule 30 (required) All automatic variables shall be assigned a value before being used.

How the rule is checked

Partial support for checking this rule is available in the implementation.

The compiler will generate an error, indicating a violation of this rule, if a variable is used but not previously assigned a value, but only if no execution path contains an assignment.

Rule 31 (required) Braces shall be used to indicate and match the structure in the non-zero initialization of arrays and structures.

How the rule is checked

The compiler will generate an error, indicating a violation of this rule, for any initializer that does not have the correct brace structure and number of elements. The compiler will not generate an error if the initializer { 0 } is used.

Examples of rule violations

struct { int a,b; } a_struct = { 1 }; struct { int a[3]; } a_struct = { 1, 2 };

Examples of correct code

struct { int a,b; } a_struct = { 1, 2 }; struct { int a,b; } a_struct = { 0 }; struct { int a[3]; } a_struct = { 0 };

IAR Embedded Workbench® MISRA C

26 Reference Guide

Соседние файлы в папке MISRA