MISRA Discussion Forums
9.3 and {0} - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.9 Initialization (https://forum.misra.org.uk/forumdisplay.php?fid=164)
+---- Thread: 9.3 and {0} (/showthread.php?tid=982)



9.3 and {0} - gs - 11-09-2013

Would the following example be compliant with rule #9.3?
Code:
int a[3][2] = {0};



Re: 9.3 and {0} - misra-c - 12-09-2013

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.



Re: 9.3 and {0} - lovewar - 20-03-2015

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};



Re: 9.3 and {0} - misra-c - 01-04-2015

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 */