Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
Warning when trying to initialize a 2D struct array with two initializer lists

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

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

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

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

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

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

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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 C11 specs, 6.7.9 Initialization grammar

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

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

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

From the same section:

[16] Otherwise, the initializer for an object that has aggregate or union type shall be a brace enclosed list of initializers for the elements or named members.

[20] If the aggregate or union contains elements or members that are aggregates or unions, these rules apply recursively to the subaggregates or contained unions. If the initializer of a subaggregate or contained union begins with a left brace, the initializers enclosed by that brace and its matching right brace initialize the elements or members of the subaggregate or the contained union. Otherwise, only enough initializers from the list are taken to account for the elements or members of the subaggregate or the first member of the contained union; any remaining initializers are left to initialize the next element or member of the aggregate of which the current subaggregate or contained union is a part.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!