4

When I build my project for an Android shared library in Visual Studio, I got a warning message below.

warning : suggest braces around initialization of subobject
[-Wmissing-braces]

This message is indicating an array initialization statement which uses only a pair of braces.

int myArray[ROW][COL] = { 1, 2, 3, 4, 5, 6, ..., 451, 452, 453 };

The reason why I can't write with two pairs of them is there are possibilities for changing sizes of ROW and COL in the future.

It works fine but I'm not sure if it's okay to leave the project like this, because I've never seen such a warning message when writing code for Windows only applications.

Do I have to take this seriously?

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
Jenix
  • 2,996
  • 2
  • 29
  • 58

1 Answers1

4

What you have is called aggregate initialization via brace elision, you are perfectly fine, the code is standard compliant.

From cppreference.com:

If the aggregate initialization uses the form with the equal sign (T a = {args..}), (until C++14) the braces around the nested initializer lists may be elided (omitted), in which case as many initializer clauses as necessary are used to initialize every member or element of the corresponding subaggregate, and the subsequent initializer clauses are used to initialize the following members of the object. However, if the object has a sub-aggregate without any members (an empty struct, or a struct holding only static members), brace elision is not allowed, and an empty nested list {} must be used.

See more details here and here.

Community
  • 1
  • 1
vsoftco
  • 55,410
  • 12
  • 139
  • 252