MISRA Discussion Forums

Full Version: 9.3 and {0}
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Would the following example be compliant with rule #9.3?
Code:
int a[3][2] = {0};
Yes this is compliant.

See Exception 1:
Quote:An initializer of the form { 0 } may be used to explicitly initialize all elements of an array object or sub-object.
Would the following examples be compliant with rule #9.3?
Code:
char_t a[5] = { '\0' };

Code:
uint16_t a[3][2] = {0u};

Code:
static uint16_t glob_arr[3] = {0u};

Code:
float32_t a[3][2] = {0.0f};
Your examples are all non compliant. You may either use the { 0 } syntactic form or you can initialise all elements of the array. E.g.
Code:
static uint16_t glob_arr[3] = {0u, 0u, 0u};  /* Compliant - all items initialised */