Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA C:2012 9.3 clarification
#2
Exception 2 only applies to array objects, not the suboject of an array.

Code:
int32_t a[3] = { 1, 2, [2]=3 };             // Compliant
int32_t b[2][2] = { { 1, 2 }, { [1]=4 } };  // Non-Compliant - exception 2 does not apply to subobjects
int32_t c[3][2] = { { 1, 2 }, { 3, 4 } };   // Non-Compliant c[2] must be explicitly represented as {0}
int32_t d[1][2] = { [0][1]=2, [0]={1} };    // Non-Compliant as [0]={1} does not fully initialise [0]
int32_t e[1][2] = { [0]={1}, [0][1]=2 };    // Non-Compliant as [0]={1} does not fully initialise [0]
int32_t f[3][2] = { [1]={3, 4}, { 5, 6 }, [0][1]=2, [0][0]=1 };  // Compliant
int32_t g[2][2] = { { 1, 2 }, [1][0]=3, 4 };  // Compliant with 9.4, but Non-Compliant with 9.2 (see example z3)
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)