enum TAG name1 [ := constant_expression1 ], name2 [ := constant_expression2 ], name3, name4, ... endenum |
An enumeration generates a list of constants. If the value of an enumerated constant is not specified (as in name3 and name4 above), the constant value is assigned the next integer after the value of the previous enumeration. If no value is specified for the first enumerated value, 0 will be used.
Strings can also be used. The assumed-constant value will be incremented, but not assigned to the enumerated value.
It's safe to ignore that paragraph, and just look at the examples below.
The following code: | Generates the following constants: |
enum FOO FOO_A, FOO_B, FOO_C endenum |
FOO_A := 0; FOO_B := 1; FOO_C := 0; |
enum FOO FOO_A := 2, FOO_B, FOO_C endenum |
FOO_A := 2; FOO_B := 3; FOO_C := 4; |
enum FOO FOO_A, FOO_B, FOO_C := 8, FOO_D endenum |
FOO_A := 0; FOO_B := 1; FOO_C := 8; FOO_D := 9; |
enum FOO FOO_A, FOO_B, FOO_C := FOO_B + 8, FOO_D endenum |
FOO_A := 0; FOO_B := 1; FOO_C := 9; FOO_D := 10; |
enum FOO FOO_A := 1, FOO_B, FOO_C, FOO_COUNT := FOO_C endenum |
FOO_A := 1; FOO_B := 2; FOO_C := 3; FOO_COUNT := 3; |