Skip Navigation Links | |
Exit Print View | |
Oracle Solaris Studio 12.3: C++ User's Guide Oracle Solaris Studio 12.3 Information Library |
3. Using the C++ Compiler Options
4.1.1 Compatibility with Microsoft Windows
4.3 Overriding With Less Restrictive Virtual Functions
4.5 Using Incomplete enum Types
4.6 Using an enum Name as a Scope Qualifier
4.7 Using Anonymous struct Declarations
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
4.11.1 __packed__ Attribute Details
4.12 Compiler Support for Intel MMX and Extended x86 Platform Intrinsics
6. Creating and Using Templates
9. Improving Program Performance
10. Building Multithreaded Programs
12. Using the C++ Standard Library
When you use -features=extensions, the compiler allows the forward declaration of enum types and variables. In addition, the compiler allows the declaration of a variable with an incomplete enum type. The compiler will always assume an incomplete enum type to have the same size and range as type int on the current platform.
The following two lines show an example of invalid code that will compile when you use the -features=extensions option.
enum E; // invalid: forward declaration of enum not allowed E e; // invalid: type E is incomplete
Because enum definitions cannot reference one another, and no enum definition can cross-reference another type, the forward declaration of an enumeration type is never necessary. To make the code valid, you can always provide the full definition of the enum before it is used.
Note - On 64-bit architectures, enum can require a size that is larger than type int. If that is the case, and if the forward declaration and the definition are visible in the same compilation, the compiler will emit an error. If the actual size is not the assumed size and the compiler does not see the discrepancy, the code will compile and link, but might not run properly. Unexpected program behavior can occur, particularly if an 8-byte value is stored in a 4-byte variable.