Enumerations

An enumeration is a data type consisting of a set of values that are named integral constants. It is also referred to as an enumerated type because you must list (enumerate) each of the values in creating a name for each of them. A named value in an enumeration is called an enumeration constant. In addition to providing a way of defining and grouping sets of integral constants, enumerations are useful for variables that have a small number of possible values.

You can define an enumeration data type and all variables that have that enumeration type in one statement, or you can declare an enumeration type separately from the definition of variables of that type. The identifier associated with the data type (not an object) is called an enumeration tag. Each distinct enumeration is a different enumeration type.

Compatible Enumerations

C In C, each enumerated type must be compatible with the integer type that represents it. Enumeration variables and constants are treated by the compiler as integer types. Consequently, in C you can freely mix the values of different enumerated types, regardless of type compatibility.

Linux C Compatibility between an enumerated type and the integer type that represents it is controlled by compiler options and related pragmas. For a full discussion of the enum compiler option and related #pragmas, see XL C/C++ Compiler Reference

C++ C++ treats enumerated types as distinct from each other and from integer types. You must explicitly cast an integer in order to use it as an enumeration value.

Related References

IBM Copyright 2003