/* >>>------------------------------------------------------------ * * File: rule_9.2.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 9.2 (Required): * Braces shall be used to indicate and match the structure in the * non-zero initialisation of arrays and structures. * * Implemented by messages: * 686 Array has fewer initializers than its declared size. * Default initialization is applied to the remainder of * the array elements. * * 693 Struct initializer is missing the optional {. * * 694 Array initializer is missing the optional {. * * <<<------------------------------------------------------------ */ /* PRQA S 703,3205 ++ */ #include "misra.h" #include "m2cmex.h" struct base1 { S16 i; S16 j; }; struct base2 { S16 a[3]; U16 b[2]; }; extern S16 test_0902( void ) { struct base1 s[4] = { 0 }; /* OK */ struct base1 t[4] = { 1 }; /* MISRA Violation */ struct base1 u[4] = { 1, 2 }; /* MISRA Violation */ struct base1 v[3] = { { 1, 1 }, 2, 2, { 3, 3 } }; /* MISRA Violation */ struct base2 x = { { 4, 5, 6 }, { 7U, 8U } }; /* OK */ struct base2 y = { 4, 5, 6, 7U, 8U }; /* MISRA Violation */ struct base2 z = { { {4, 5, 6}, {7U, 8U} } }; /* MISRA Violation */ S16 p[2][2] = { { 1, 2 }, { 3, 4 } } ; /* OK */ S16 q[2][2] = { 1, 2, 3, 4 }; /* MISRA Violation */ S16 r[4] = { 1, 2, 3 }; return 0; }