Enumerated Integer Types
An enumerated type declaration, enum, is treated as an integer declaration. The syntax of an enumerated type declaration is:
enum [enum_tag]
{ enumerator [= integer_literal]
{, enumerator [= integer_literal]} } [enum_vars];
The outermost braces ( { and } ) represent actual braces you type.
Syntax Notes:
• If you use the enum_tag, the list of enumerated literals (enumerators) and enum variables (enum_vars) is optional, as in a structure declaration. The two declarations that follow are equivalent. The first declaration declares an enum_tag, while the second declaration uses that tag to declare a variable.
First declaration:
## enum color {RED, WHITE, BLUE};
/* Tag, no variable */
## enum color col; /* Tag, no body, has variable */
Second declaration:
## enum color {RED, WHITE, BLUE} col;
/* Tag, body, has variable */
If you do not use the enum_tag, the declaration must include a list of enumerators, as in a structure declaration.
• You can use the enum declaration with any other variable declaration, type declaration, or storage class. For example, the following declarations are all legal:
## typedef enum {dbTABLE, dbCOLUMN, dbROW,
## dbVIEW, dbGRANT} dbOBJ;
## dbOBJ obj, objs[10];
## extern dbOBJ *obj_ptr;
• Enumerated variables are treated as integer variables and enumerated literals are treated as integer constants.