|
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!
|