ENUMSIZE
Category
Floating-point and integer control
Pragma equivalent
#pragma enum
Purpose
Specifies the amount of storage occupied by enumerations
Syntax
Defaults
ENUM(SMALL)
Parameters
- SMALL
- Specifies that enumerations occupy a minimum amount of storage,
which is either 1, 2, 4, or 8 bytes of storage, depending on the range
of the
enum
constants. - INT
- Specifies that enumerations occupy 4 bytes of storage and are
represented by
int
. - INTLONG
- Valid only when LP64 is specified and for C++ only. It specifies
that enumerations occupy 8 bytes of storage and are represented by
long
if the range of theenum
constants exceed the limit forint
. Otherwise, the enumerations occupy 4 bytes of storage and are represented byint
. - 1
- Specifies that enumerations occupy 1 byte of storage.
- 2
- Specifies that enumerations occupy 2 bytes of storage
- 4
- Specifies that enumerations occupy 4 bytes of storage.
- 8
- Specifies that enumerations occupy 8 bytes of storage. This suboption is only valid with LP64.
Usage
When the ENUMSIZE option is in effect, you can select the type
used to represent all enum
constants defined in
a compilation unit.
The following tables illustrate the preferred sign and type for
each range of enum
constants:
ENUM Constants | small | 1 | 2 | 4 | 8 * | int | intlong * (C++ only) |
---|---|---|---|---|---|---|---|
0..127 | unsigned char | signed char | short | int | long | int | int |
-128..127 | signed char | signed char | short | int | long | int | int |
0..255 | unsigned char | unsigned char | short | int | long | int | int |
0..32767 | unsigned short | ERROR | short | int | long | int | int |
-32768..32767 | short | ERROR | short | int | long | int | int |
0..65535 | unsigned short | ERROR | unsigned short | int | long | int | int |
0..2147483647 | unsigned int | ERROR | ERROR | int | long | int | int |
-231..231-1 | int | ERROR | ERROR | int | long | int | int |
0..4294967295 | unsigned int | ERROR | ERROR | unsigned int | long | unsigned int (C++ only) ERROR for C | unsigned int |
0..(263-1) * | unsigned long | ERROR | ERROR | ERROR | long | ERROR | long |
-263..(263-1) * | long | ERROR | ERROR | ERROR | long | ERROR | long |
0..264 * | unsigned long | ERROR | ERROR | ERROR | unsigned long | ERROR | unsigned long |
Note: The rows and columns marked with asterisks (*) in
this table are only valid when the LP64 option is in effect.
The usage status of this option is inserted in the object file to aid you in diagnosing a problem with your program.
Predefined macros
The __ENUM_OPT macro is defined only by the C compiler, which predefines it to 1 when the ENUMSIZE option is in effect; otherwise it is undefined.
Examples
If the specified storage size is smaller than that required
by the range of enum
constants, an error is issued by the
compiler; for example:
#include <limits.h>
#pragma enum(1)
enum e_tag {
a = 0,
b = SHRT_MAX /* error */
} e_var;
#pragma enum(reset)