Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

93
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda