JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.2: C++ User's Guide
search filter icon
search icon

Document Information


Part I C++ Compiler

1.  The C++ Compiler

2.  Using the C++ Compiler

3.  Using the C++ Compiler Options

Part II Writing C++ Programs

4.  Language Extensions

4.1 Linker Scoping

4.1.1 Compatibility with Microsoft Windows

4.2 Thread-Local Storage

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.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 Supported Attributes

4.11.1 __packed__

5.  Program Organization

6.  Creating and Using Templates

7.  Compiling Templates

8.  Exception Handling

9.  Improving Program Performance

10.  Building Multithreaded Programs

Part III Libraries

11.  Using Libraries

12.  Using The C++ Standard Library

13.  Using the Classic iostream Library

14.  Using the Complex Arithmetic Library

15.  Building Libraries

Part IV Appendixes

A.  C++ Compiler Options

B.  Pragmas



4.4 Making Forward Declarations of enum Types and Variables

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, it is possible for an enum to 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. Mysterious program behavior can occur, particularly if an 8-byte value is stored in a 4-byte variable.