Search
Support & Downloads
All of Support
This Category
Software Products
Performance Tools for Software Developers
Designated Initializers in C++ Mode

C99 introduces the feature of designated initializers, which allows specific members of structures, unions, or arrays to be initialized explicitly by name or subscript. C++ does not support this feature, but it might be provided as an extension by some C++ compilers; but would probably be valid only for POD structure types and arrays of POD (plain old data) types. GNU GCC support this feature in C++ for non-POD types. Intel® C++ Compiler 10.x does not support this any more.

Example:

$ cat t.cpp:

struct S { S(); ~S(); };
struct S S1[3] = { [2] = S() };

$ icpc -c t.cpp

t.cpp(3): error #2084: designator may not specify a non-POD (Plain Old Data) subobject

struct S S[3] = { [2] = S() };

compilation aborted for t.cpp (code 2)

The struct S is declared with a default constructor, i.e. S() and a destructor ~S(). This is not valid C - in C you cannot have functions declared inside structures - and it makes the structure a non-POD type.

This declares an object named S1 with type array of 3 S structs and you are initializing the second element of the array (which is a struct S type) using the default constructor for S.

This applies to:
Intel® C++ Compiler for Linux*
Intel® C++ Compiler for Mac OS*

Solution ID: CS-025651
Date Created: 04-Mar-2007
Last Modified: 05-Jun-2007
Back to Top