Warning when trying to initialize an array of a 2D structure with two lists of initializers

I am trying to initialize a 2D array of a user-defined type to zero using the following line,

qmf_t X_hybrid_left[32][32] = {{0}}; 

Where qmf_t is the user-defined type. Here I get a compiler warning,

warning: missing curly braces around the initializer [-Wmissing-braces] "

But if I use, qmf_t X_hybrid_left[32][32] = {{{0}}}; , i.e. 3 bindings on each side, the warning disappears.

Is it right to use three curly braces on each side? What does it mean?

+5
source share
1 answer
 qmf_t X_hybrid_left[32][32] = { /* Row initializers next */ { /* Col initializers next */ { /* Struct initializers next */ 0 } } }; qmf_t a = {0}; qmf_t b[5] = {{0}}; qmf_t c[10][5] = {{{0}}}; 

From specifications C11, 6.7.9. Initialization .

initializer:
Assignment expression
{initializer-list}
{initializer-list,}

Although in your particular case (zeroing all objects from 2 arrays), qmf_t X_hybrid_left[32][32] = {0}; will work the same as qmf_t X_hybrid_left[32][32] = {{{0}}}; but the compiler can warn you.

But if you want any non-zero initialization, you need to use several curly braces.

In the same section:

[16] Otherwise, the initializer for an object that has an aggregate or type of union must be in parenthesized list of initializers for elements or named elements.

[20] If an aggregate or association contains elements or elements that are aggregates or unions, these rules apply recursively to subaggregates or combined unions. If the initializer sub-aggregate or containing the union begins with the left bracket, the initializers enclosed in this bracket and the corresponding right bracket initialize the elements or elements of the sub-aggregate or containing the union. Otherwise, only initializers from the list are enough. accepted for accounting elements or members of a sub-aggregate or the first member of a joint union; any remaining initializers to initialize the next element or member of the population that is part of or a combined element.

+12
source

All Articles