Enumerations consist of the enum
keyword and an optional identifier followed by an enumerator-list enclosed by braces.
An identifier is of type int
.
The enumerator-list has at least one enumerator element.
An enumerator may optionally be "assigned" a constant expression of type int
.
An enumerator is constant and is compatible to either a char
, a signed integer or an unsigned integer. Which ever is used is implementation-defined. In any case the type used should be able to represent all values defined for the enumeration in question.
If no constant expression is "assigned" to an enumerator and it is the 1st entry in an enumerator-list it takes value of 0
, else it get takes the value of the previous entry in the enumerator-list plus 1.
Using multiple "assignments" can lead to different enumerators of the same enumeration carry the same values.