Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
9.3 and {0}
#1
Would the following example be compliant with rule #9.3?
Code:
int a[3][2] = {0};
Reply
#2
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.
Posted by and on behalf of the MISRA C Working Group
Reply
#3
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};
<t></t>
Reply
#4
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 */
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)