#pragma options enum, #pragma enum
Specifies the amount of storage occupied by enumerations.
Option syntax .-intlong-. >>- -q--enum--=--+-int-----+----------------------------------->< +-small---+ +-1-------+ +-2-------+ +-4-------+ '-8-------'
Pragma syntax .-intlong-. >>-#--pragma--enum----(--+-int-----+--)------------------------>< +-small---+ +-1-------+ +-2-------+ +-4-------+ +-8-------+ +-pop-----+ '-reset---'
-qenum=intlong
Values cannot exceed
the range of signed int.
Specifies that enumerations
occupy 4 bytes of storage and are of type int.
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.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. 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 | signed char | int | short | int | int | int | long long | long long | long | long |
| -128..127 | signed 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 int2 | ERROR1 | unsigned int2 | unsigned int2 | unsigned int2 | long long | long long | long | long |
| 0..(263-1) | ERROR1 | long2 | ERROR1 | long2 | ERROR1 | long2 | long long2 | long long2 | long2 | long2 |
| -263..(263-1) | ERROR1 | long2 | ERROR1 | long2 | ERROR1 | long2 | long long2 | long long2 | long2 | long2 |
| 0..264 | ERROR1 | unsigned long2 | ERROR1 | unsigned long2 | ERROR1 | unsigned long2 | unsigned long long2 | unsigned long long2 | unsigned long2 | unsigned long2 |
| 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 int1 | unsigned int2 | unsigned int2 | unsigned int2 | unsigned int2 | unsigned int2 | unsigned int2 | unsigned int2 | unsigned int2 | unsigned int2 |
| 0..(263-1) | ERR2 | ERR2 | long long2 | long long2 | long2 | long2 | unsigned long long2 | unsigned long long2 | unsigned long2 | unsigned long2 |
| -263..(263-1) | ERR2 | ERR2 | long long2 | long long2 | long2 | long2 | long long2 | long long2 | long2 | long2 |
| 0..264 | ERR2 | ERR2 | unsigned long long2 | unsigned long long2 | unsigned long2 | unsigned long2 | unsigned long long2 | unsigned long long2 | unsigned long2 | unsigned long2 |
int
setting. A Severe error
is issued and compilation stops. To correct this condition, you should
reduce the range of the enumerations, choose a larger -qenum setting,
or choose a dynamic -qenum setting, such as small or intlong.
Enumeration types must not exceed the range of int when
compiling C applications to ISO C 1989 and ISO C 1999 Standards. With
the stdc89 | stdc99 language level in effect, the compiler
will behave as follows if the value of an enumeration exceeds the
range of int and the -qenum option in effect
supports this value: The #pragma enum directive must be precede the declaration of enum variables that follow; any directives that occur within a declaration are ignored and diagnosed with a warning.
For each #pragma enum directive that you put in a source file, it is good practice to have a corresponding #pragma enum=reset before the end of that file. This should prevent one file from potentially changing the setting of another file that includes it.
enum e_tag {a, b, c} e_var;
the
range of enumeration constants is 0 through 2. This range falls within
all of the ranges described in the table above. Based on priority,
the compiler uses predefined type unsigned char. enum e_tag {a=-129, b, c} e_var;
the range
of enumeration constants is -129 through -127. This range only falls
within the ranges of short (signed short) and int
(signed int). Because short (signed short) is
smaller, it will be used to represent the enum. #pragma enum=small
enum e_tag {
a,
b,
#pragma enum=int /* error: cannot be within a declaration */
c
} e_var;
#pragma enum=reset
#pragma enum=reset /* second reset isn't required */
None.