3. Using the C++ Compiler Options
4.1.1 Compatibility with Microsoft Windows
4.3 Overriding With Less Restrictive Virtual Functions
4.4 Making Forward Declarations of enum Types and Variables
4.5 Using Incomplete enum Types
4.6 Using an enum Name as a Scope Qualifier
4.8 Passing the Address of an Anonymous Class Instance
4.9 Declaring a Static Namespace-Scope Function as a Class Friend
4.10 Using the Predefined __func__ Symbol for Function Name
6. Creating and Using Templates
9. Improving Program Performance
10. Building Multithreaded Programs
12. Using The C++ Standard Library
13. Using the Classic iostream Library
An anonymous struct declaration is a declaration that declares neither a tag for the struct, nor an object or typedef name. Anonymous structs are not allowed in C++.
The -features=extensions option allows the use of an anonymous struct declaration, but only as member of a union.
The following code is an example of an invalid anonymous struct declaration that compiles when you use the -features=extensions option.
union U { struct { int a; double b; }; // invalid: anonymous struct struct { char* c; unsigned d; }; // invalid: anonymous struct };
The names of the struct members are visible without qualification by a struct member name. Given the definition of U in this code example, you can write:
U u; u.a = 1;
Anonymous structs are subject to the same limitations as anonymous unions.
Note that you can make the code valid by giving a name to each struct, such as:
union U { struct { int a; double b; } A; struct { char* c; unsigned d; } B; }; U u; U.A.a = 1;