MISRA C:2012 9.3 clarification - 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: MISRA C:2012 9.3 clarification (/showthread.php?tid=1555) |
MISRA C:2012 9.3 clarification - mcks - 24-11-2020 I try to implement the checks for "9.3 - Arrays shall not be partially initialized" in Cppcheck, and would like to have some clarifications. Is it ok to mix initializers like this, as long as every element gets initialized? int32_t a[3] = { 1, 2, [2]=3 }; For multi-dimensional arrays, this would be compliant: int32_t b[2][2] = { { 1, 2 }, { [1]=4 } }; beacuse b[1] is initialized with only a designated initializer. As for c, both the array subobjects c[0] and c[1] are fully initialized, but there is no initialization of c[2]. Does that make the statement non-compliant? int32_t c[3][2] = { { 1, 2 }, { 3, 4 } }; What about the arrays below, are they compliant or not, and why? Also, are they violatin 9.2 or 9.4? int32_t d[1][2] = { [0][1]=2, [0]={1} }; int32_t e[1][2] = { [0]={1}, [0][1]=2 }; int32_t f[3][2] = { [1]={3, 4}, { 5, 6 }, [0][1]=2, [0][0]=1 }; int32_t g[2][2] = { { 1, 2 }, [1][0]=3, 4 }; Let me know what you think. If you have more (tricky) examples, then please share! RE: MISRA C:2012 9.3 clarification - misra-c - 21-08-2021 Exception 2 only applies to array objects, not the suboject of an array. Code: int32_t a[3] = { 1, 2, [2]=3 }; // Compliant |