2 ms·
The designated initializers example will actually compile in recent versions of GCC, Clang, and Visual C++, even if that's not part of the standard prior to C++
by pietroglyph 7y ago
The designated initializers example will actually compile in recent versions of GCC, Clang, and Visual C++, even if that's not part of the standard prior to C++20. A better example (i.e. one that doesn't compile in C++ but does in C) would be
int arr[3] = { [1] = 5 }
or even
struct A c = {.x = 1, 2}
or another example where the designators are not declared in order of the struct members, or where the designators are nested. The version of designated initializers standardized in C++20 only allows the simple case that's currently implemented in all the major compilers.
See https://stackoverflow.com/a/29337570 https://stackoverflow.com/a/29337570 for more info and examples.