Specifies the amount of storage occupied by enumerations.
Syntax Notes:
- C compilation default
- C++ compilation default
where valid enum settings are:
1 Specifies that enumerations occupy 1 byte of storage, are of type char if the range of enumeration values falls within the limits of signed char, and unsigned char otherwise. 2 Specifies that enumerations occupy 2 bytes of storage, are of type short if the range of enumeration values falls within the limits of signed short, and unsigned short otherwise. 4 Specifies that enumerations occupy 4 bytes of storage are of type int if the range of enumeration values falls within the limits of signed int, and unsigned int otherwise. 8 Specifies that enumerations occupy 8 bytes of storage.
In 32-bit compilation mode, the enumeration is of type long long if the range of enumeration values falls within the limits of signed long long, and unsigned long long otherwise.
In 64-bit compilation mode, the enumeration is of type long if the range of enumeration values falls within the limits of signed long, and unsigned long otherwise.int Specifies that enumerations occupy 4 bytes of storage and are represented by int. Values cannot exceed the range of signed int in C compilations. intlong Specifies that enumerations will occupy 8 bytes of storage if the range of values in the enumeration exceeds the limit for int. See the description for -qenum=8.
If the range of values in the enumeration does not exceed the limit for int, the enumeration will occupy 4 bytes of storage and is represented by int.small Specifies that enumerations occupy the smallest amount of space (1, 2, 4, or 8 bytes of storage) that can accurately represent the range of values in the enumeration. Signage is unsigned, unless the range of values includes negative values.
If an 8-byte enum results, the actual enumeration type used is dependent on compilation mode. See the description for -qenum=8
See also #pragma enum and #pragma options.
The -qenum=small option allocates to an enum variable the amount of storage that is required by the smallest predefined type that can represent that range of enum constants. By default, an unsigned predefined type is used. If any enum constant is negative, a signed predefined type is used.
The -qenum=1|2|4|8 options allocate a specific amount of storage to an enum variable. If the specified storage size is smaller than that required by the range of enum variables, a Severe error message is issued and compilation stops.
The ISO C 1989 and ISO C1999 Standards require that enumeration values not exceed the range of int. When compiling with -qlanglvl=stdc89 or -qlanglvl=stdc99 in effect, the compiler will behave as follows if the value of an enumeration exceeds the range of int:
The tables that follow show the priority for selecting a predefined type. The table also shows the predefined type, the maximum range of enum constants for the corresponding predefined type, and the amount of storage that is required for that predefined type, that is, the value that the sizeof operator would yield when applied to the minimum-sized enum.
Compiler Command Line Options
#pragma enum
#pragma options
Enum sizes and types - All types are signed unless otherwise noted. | ||||||||||
enum=1 | enum=2 | enum=4 | enum=8 | |||||||
32-bit compilation mode | 64-bit compilation mode | |||||||||
Range | var | const | var | const | var | const | var | const | var | const |
0..127 | char | int | short | int | int | int | long long | long long | long | long |
-128..127 | char | int | short | int | int | int | long long | long long | long | long |
0..255 | unsigned char | int | short | int | int | int | long long | long long | long | long |
0..32767 | ERROR1 | int | short | int | int | int | long long | long long | long | long |
-32768..32767 | ERROR1 | int | short | int | int | int | long long | long long | long | long |
0..65535 | ERROR1 | int | unsigned short | int | int | int | long long | long long | long | long |
0..2147483647 | ERROR1 | int | ERROR1 | int | int | int | long long | long long | long | long |
-(2147483647+1) ..2147483647 | ERROR1 | int | ERROR1 | int | int | int | long long | long long | long | long |
0..4294967295 | ERROR1 | unsigned int | ERROR1 | unsigned int | unsigned int | unsigned int | long long | long long | long | long |
0..(263-1) | ERROR1 | long2b | ERROR1 | long2b | ERROR1 | long2b | long long2b | long long2b | long2b | long2b |
-263..(263-1) | ERROR1 | long2b | ERROR1 | long2b | ERROR1 | long2b | long long2b | long long2b | long2b | long2b |
0..264 | ERROR1 | unsigned long2b | ERROR1 | unsigned long2b | ERROR1 | unsigned long2b | unsigned long long2b | unsigned long long2b | unsigned long2b | unsigned long2b |
Notes:
|
Enum sizes and types - All types are signed unless otherwise noted. | ||||||||||
enum=int | enum=intlong | enum=small | ||||||||
32-bit compilation mode | 64-bit compilation mode | 32-bit compilation mode | 64-bit compilation mode | |||||||
Range | var | const | var | const | var | const | var | const | var | const |
0..127 | int | int | int | int | int | int | unsigned char | int | unsigned char | int |
-128..127 | int | int | int | int | int | int | signed char | int | signed char | int |
0..255 | int | int | int | int | int | int | unsigned char | int | unsigned char | int |
0..32767 | int | int | int | int | int | int | unsigned short | int | unsigned short | int |
-32768..32767 | int | int | int | int | int | int | short | int | short | int |
0..65535 | int | int | int | int | int | int | unsigned short | int | unsigned short | int |
0..2147483647 | int | int | int | int | int | int | unsigned int | unsigned int | unsigned int | unsigned int |
-(2147483647+1) ..2147483647 | int | int | int | int | int | int | int | int | int | int |
0..4294967295 | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int |
0..(263-1) | ERR2a | ERR2a | long long2b | long long2b | long2b | long2b | unsigned long long2b | unsigned long long2b | unsigned long2b | unsigned long2b |
-263..(263-1) | ERR2a | ERR2a | long long2b | long long2b | long2b | long2b | long long2b | long long2b | long2b | long2b |
0..264 | ERR2a | ERR2a | unsigned long long2b | unsigned long long2b | unsigned long2b | unsigned long2b | unsigned long long2b | unsigned long long2b | unsigned long2b | unsigned long2b |
Notes:
|