Enumeration specifiers

Previous Table of Contents "New C Standard" commentary


                enum identifieropt { enumerator-list }
                enum identifieropt { enumerator-list , }
                enum identifier

enumerator-list: enumerator enumerator-list , enumerator

enumerator: enumeration-constant enumeration-constant = constant-expression

1440 The expression that defines the value of an enumeration constant shall be an integer constant expression that has a value representable as an int.

1441 The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted.107)

1442 An enumerator with = defines its enumeration constant as the value of the constant expression.

1443 If the first enumerator has no =, the value of its enumeration constant is 0.

1444 Each subsequent enumerator with no = defines its enumeration constant as the value of the constant expression obtained by adding 1 to the value of the previous enumeration constant.

1445 (The use of enumerators with = may produce enumeration constants with values that duplicate other values in the same enumeration.)

1446 The enumerators of an enumeration are also known as its members.

1447 Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type.

1448 The choice of type is implementation-defined,108) but shall be capable of representing the values of all the members of the enumeration.

1449 The enumerated type is incomplete until after the } that terminates the list of enumerator declarations.

1450 EXAMPLE The following fragment:

        enum hue { chartreuse, burgundy, claret=20, winedark };
        enum hue col, *cp;
        col = claret;
        cp = & col;
        if (*cp != burgundy)
                /* ... */

makes hue the tag of an enumeration, and then declares col as an object that has that type and cp as a pointer to an object that has that type. The enumerated values are in the set { 0, 1, 20, 21 }.

1451 Forward references: tags (

1452 107) Thus, the identifiers of enumeration constants declared in the same scope shall all be distinct from each other and from other identifiers declared in ordinary declarators.

1453 108) An implementation may delay the choice of which integer type until all enumeration constants have been seen.


Created at: 2008-01-30 02:39:43 The text from WG14/N1256 is copyright © ISO