Declaring an Enumeration Data Type

An enumeration type declaration contains the enum keyword followed by an optional identifier (the enumeration tag) and a brace-enclosed list of enumerators. Commas separate each enumerator in the enumerator list. C99 allows a trailing comma between the last enumerator and the closing brace. A declaration of an enumeration has the form:

                            .-,----------.
                            V            |
>>-enum--+------------+--{----enumerator-+--}--;---------------><
         '-identifier-'
 
 

The keyword enum, followed by the identifier, names the data type (like the tag on a struct data type). The list of enumerators provides the data type with a set of values.

In C, each enumerator represents an integer value. In C++, each enumerator represents a value that can be converted to an integral value.

An enumerator has the form:

>>-identifier--+---------------------------------+-------------><
               '-=--integral_constant_expression-'
 
 

To conserve space, enumerations may be stored in spaces smaller than that of an int. IBM Copyright 2003