6.7.2.2 Enumeration specifiers

Previous Table of Contents

1429

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

enumerator-list: enumerator enumerator-list , enumerator

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

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

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

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

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

1434 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.

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

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

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

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

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

1440 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 }.

1441 Forward references: tags (6.7.2.3).

1442 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.

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

Next

Created at: 2005-06-29 02:19:01 The text from WG14/N1124 is copyright © ISO