Initialization of the form { 0 } in relation to Rule 11.9

Moderators: misra-c, david ward

Post Reply
rgamble
Posts: 14
Joined: Fri Jul 20, 2007 7:54 pm

Initialization of the form { 0 } in relation to Rule 11.9

Post by rgamble » Sun Jun 15, 2014 4:47 am

Is the following example intended to be a violation of Rule 11.9?

Code: Select all

#include <stdint.h>

void f(void) { 
    uint16_t * var[10] = { 0 };  // violates 11.9?
}
While a strict interpretation seems to suggest this a technically a violation, Rule 9.2 specifically allows for an initializer of the form { 0 } which indicates that this (being a violation of 11.9) may not have been intended.

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

Re: Initialization of the form { 0 } in relation to Rule 11.

Post by misra-c » Wed Jun 25, 2014 6:11 pm

An exception should be present in rule 11.9 to permit the initialisation of array of pointers with "{0}". This is consistent with rule 9.2 and the exception to rule 10.3 for array of floats.

Code: Select all

float_32 farr_ok1[3] = {0};                 // compliant
float_32 farr_ok2[3] = {0.0f, 0.0f, 0.0f};  // compliant
float_32 farr_nok[3] = {0.0f};              // not compliant with Rule 9.3 
 
int_32 * ptr_ok1[3] = {0};                  // compliant
int_32 * ptr_ok2[3] = {NULL, NULL, NULL};   // compliant
int_32 * ptr_nok[3] = {NULL};               // not compliant with Rule 9.3
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.11 Pointer type conversions”