Enumerated type
Enumeration statement:
ENUM logo enumeration body
ENUM enumeration body
ENUM logo: Enumerate basic type enumeration body
ENUM enumeration basic type: enumeration body
Enumerate basic type:
Types of
Enumerator:
;
{Multiple enumeration members}
Multiple enumeration members:
Enumerate
Enumerate members,
Enumerate members, multiple enumeration members
Enumerates:
Marker
Flag = expression
ENUMDECLATION:
ENUM IDENTIFIER ENUMBOMBODY
ENUM ENUMBODY
ENUM IDENTIFIER: ENUMBASETYPE ENUMBODY
ENUM ENUMBASEPE: ENUMBODY
ENUMBASEPE:
Type
ENUMBODY:
;
{Enummembers}
ENUMMEMBERS:
ENUMMEMBER
ENUMMEMBER,
ENUMMEMBER, ENUMMEMBERS
ENUMMEMBER:
Identifier
Identifier = Expression
Enumerates to define a set of related integer constants.
If the Enum flag is specified, multiple enumeration members are declared within the scope of the ENUM flag. The Enum flag declares a new type.
If the enum flag is not specified, the enumeration is called anonymous enumeration, and multiple enumeration members are declared in the scope of enumeration declaration. No new types are created; multiple enumeration members are enumerated basic types.
Enumeration The basic type is the basic type of enumeration. It must be an integer type. If ignored, the default is int.
ENUM {a, b, c} // anonymous enumeration
Define constant a = 0, b = 1, c = 2:
Const int A = 0;
Const Int B = 1;
Const Int C = 2;
Equivalent to:
Enum x {a, b, c} // name enumeration
This defines the new type X, the owned value x.a = 0, X.B = 1, X.c = 2.
Naming enumeration members can be implicitly converted to integer types, but integer types cannot be implicitly converted to enumeration types.
Enumeration must have at least one member.
If an enumeration member is given an expression, the value of the members of the town is the result of the expression. The expression must be determined when compiling. The value of subsequent enumeration members of the subsequent representation is the previous member plus one.
Enum {a, b = 5 7, c, d = 8, e}
This makes A = 0, B = 12, C = 13, D = 8, E = 9.
Enumeration properties
The minimum value of .min enumeration
.max enumeration maximum
.sizeof storage enumeration value required memory size
E.g:
X.min is x.a
X.max is x.c
X.SizeOf equivalent in int.sizeof
Initialization of enumeration If no explicit initialization, the value of enumeration variable is initialized to the value of the first enumeration member.
Enum x {a = 3, b, c}
X x; // x is initialized to 3