GCC Designated Initializers support?

Hi,

Am I using GCC designated initializer incorrectly or is it not supported?

Trying to initialize a couple of arrays with the following

#define MAXALSSIZE 10
uint16_t aslMap[MAXALSSIZE] = { [0 ... MAXALSSIZE-1] = 0};
uint8_t matrixBrightnessMap[MAXALSSIZE] = { [0 ... MAXALSSIZE-1] = 0};

Compile error

error: expected identifier before numeric constant
   12 |         uint16_t aslMap[MAXALSSIZE] = { [0 ... MAXALSSIZE-1] = 0};
      |                                          ^

@johnnyfp Designated initializers are pretty limited in C++ and only supported with GNU extensions and later more generally since C++20, but only for members in declaration order, no mixing of designated/non-designated, no array indices, no nesting etc (see Aggregate initialization - cppreference.com).

You can add your stuff into a C source file and can use the full extent of C90+ designated initializers, but not in C++ source files.

1 Like