9.3 and {0}

Moderators: misra-c, david ward

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

9.3 and {0}

Post by gs » Wed Sep 11, 2013 8:58 pm

Would the following example be compliant with rule #9.3?

Code: Select all

int a[3][2] = {0};

misra-c
Posts: 561
Joined: Thu Jan 05, 2006 1:11 pm

Re: 9.3 and {0}

Post by misra-c » Thu Sep 12, 2013 9:59 am

Yes this is compliant.

See Exception 1:
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

lovewar
Posts: 10
Joined: Thu Feb 17, 2011 8:01 am
Company: .

Re: 9.3 and {0}

Post by lovewar » Fri Mar 20, 2015 1:23 am

Would the following examples be compliant with rule #9.3?

Code: Select all

char_t a[5] = { '\0' };

Code: Select all

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

Code: Select all

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

Code: Select all

float32_t a[3][2] = {0.0f};

misra-c
Posts: 561
Joined: Thu Jan 05, 2006 1:11 pm

Re: 9.3 and {0}

Post by misra-c » Wed Apr 01, 2015 12:49 pm

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: Select all

static uint16_t glob_arr[3] = {0u, 0u, 0u};  /* Compliant - all items initialised */
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.9 Initialization”