Option Type | Default Value | #pragma options | C | C++ |
-qoption | enum=int | ENUM=suboption | x | x |
Syntax
-qenum=small | -qenum=int | -qenum=intlong | -qenum=1 | -qenum=2 | -qenum=4 | -qenum=8 ENUM=SMALL | ENUM=INT | ENUM=INTLONG | ENUM=1 | ENUM=2 | ENUM=4 | ENUM=8 | ENUM=RESET
Purpose
Specifies the amount of storage occupied by enumerations.
Notes
Valid suboptions are:
-qenum=small | Specifies that enumerations occupy a minimum amount of storage: either 1, 2, or 4 bytes of storage, depending on the range of the enum constants. In 64-bit compilation mode, the enumerations can also use 8 bytes of storage. |
-qenum=int | Specifies that enumerations occupy 4 bytes of storage and are represented by int. |
![]() |
Valid only in 64-bit compiler mode. Specifies that enumerations occupy 8 bytes of storage and are represented by long, if -q64 is specified and the range of the enum constants exceed the limit for int. Otherwise, the enumerations occupy 4 bytes of storage and are represented by int. |
-qenum=1 | Specifies that enumerations occupy 1 byte of storage. |
-qenum=2 | Specifies that enumerations occupy 2 bytes of storage. |
-qenum=4 | Specifies that enumerations occupy 4 bytes of storage. |
-qenum=8 | Valid only in 64-bit compiler mode. Specifies that enumerations occupy 8 bytes of storage. |
RESET | Valid in #pragma enum statement only. Resets the enum mapping rule to the rule that was in effect before the current mapping rule. If no previous enum mapping rule was specified in the file, the rule specified when the compiler was initially invoked is used. |
The enum constants are always of type int, except for the following cases:
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, the requested size is kept but a warning is issued. For example:
enum {frog, toad=257} amph; 1506-387 (W) The enum cannot be packed to the requested size. Use a larger value for -qenum. (The enum size is 1 and the value of toad is 1)
For each #pragma options enum= directive that you put in a source file, it is good practice to have a corresponding #pragma options enum=reset before the end of that file. This is the only way to prevent one file from potentially changing the enum= setting of another file that #includes it. The #pragma enum() directive can be instead of #pragma options enum=. The two pragmas are interchangeable.
The tables below show the priority for selecting a predefined type. They also shows the 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).
In 32-bit compilation mode:
Range |
enum=int | enum=small | enum=1 | enum=2 | enum=4 | |||||
variable | constant | variable | constant | variable | constant | variable | constant | variable | constant | |
0..127 | int | int | unsigned char | int | signed char | int | short | int | int | int |
-128..127 | int | int | signed char | int | signed char | int | short | int | int | int |
0..255 | int | int | unsigned char | int | unsigned char | int | short | int | int | int |
0..32767 | int | int | unsigned short | int | unsigned short1 | int | short | int | int | int |
-32768..32767 | int | int | short | int | short1 | int | short | int | int | int |
0..65535 | int | int | unsigned short | int | unsigned short1 | int | unsigned short | int | int | int |
0..2147483647 | int | int | unsigned int | unsigned int | unsigned int1 | int | unsigned int1 | int | int | int |
-(2147483647+1)..2147483647 | int | int | int | int | int1 | int | int1 | int | int | int |
0..4294967295 | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int1 | unsigned int | unsigned int1 | unsigned int | unsigned int | unsigned int |
Notes:
In 64-bit compilation mode:
enum=int | enum=intlong![]() |
enum=small | enum=1 | enum=2 | enum=4 | enum=8 | ||||||||
Range | var | const | var | const | var | const | var | const | var | const | var | const | var | const |
0..127 | int | int | int | int | unsigned char | int | signed char | int | short | int | int | int | long | long |
-128..127 | int | int | int | int | signed char | int | signed char | int | short | int | int | int | long | long |
0..255 | int | int | int | int | unsigned char | int | unsigned char | int | short | int | int | int | long | long |
0..32767 | int | int | int | int | unsigned short | int | unsigned short1 | int | short | int | int | int | long | long |
-32768..32767 | int | int | int | int | short | int | short1 | int | short | int | int | int | long | long |
0..65535 | int | int | int | int | unsigned short | int | unsigned short1 | int | unsigned short | int | int | int | long | long |
0..2147483647 | int | int | int | int | unsigned int | unsigned int | int1 | int | int1 | int | int | int | long | long |
-(2147483647+1)..2147483647 | int | int | int | int | int | int | int1 | int | int1 | int | int | int | long | long |
0..4294967295 | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int | unsigned int1 | unsigned int | unsigned int1 | unsigned int | unsigned int | unsigned int | long | long |
0..(263-1) | ERR2 | ERR2 | long | long | unsigned long | unsigned long | long1 | long | long1 | long | long1 | long | long | long |
-263..(263-1) | ERR2 | ERR2 | long | long | long | long | long1 | long | long1 | long | long1 | long | long | long |
0..264 | ERR2 | ERR2 | unsigned long | unsigned long | unsigned long | unsigned long | unsigned long1 | unsigned long | unsigned long1 | unsigned long | unsigned long1 | unsigned long | unsigned long | unsigned long |
Notes:
The following are invalid enumerations or invalid usage of #pragma options enum=:
#pragma options enum=small enum e_tag { a=-1, b=2147483648 /* error: larger than maximum int */ } e_var; #pragma options enum=reset
#pragma options enum=small enum e_tag { a=0, b=4294967296 /* error: larger than maximum int */ } e_var; #pragma options enum=reset
A -qenum=reset option corresponding to the #pragma options enum=reset
directive does not exist. Attempting to use -qenum=reset generates a warning
message and the option is ignored.
Examples
#ifndef small_enum_h #define small_enum_h 1 /* * File small_enum.h * This enum must fit within an unsigned char type */ #pragma options enum=small enum e_tag {a, b=255}; enum e_tag u_char_e_var; /* occupies 1 byte of storage */ /* Reset the enumeration size to whatever it was before */ #pragma options enum=reset #endif
The following source file, int_file.c, includes small_enum.h:
/* * File int_file.c * Defines 4 byte enums */ #pragma options enum=int enum testing {ONE, TWO, THREE}; enum testing test_enum; /* various minimum-sized enums are declared */ #include "small_enum.h" /* return to int-sized enums. small_enum.h has reset the * enum size */ enum sushi {CALIF_ROLL, SALMON_ROLL, TUNA, SQUID, UNI}; enum sushi first_order = UNI;
The enumerations test_enum and test_order both occupy 4 bytes of storage and are of type int. The variable u_char_e_var defined in small_enum.h occupies 1 byte of storage and is represented by an unsigned char data type.
enum e_tag {a, b, c} e_var;
the range of enum 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 enum constants is -129 through -127. This range only falls within the ranges of short (signed short) and int (signed int). Because short (signed short) smaller, it will be used to represent the enum.
xlC myprogram.c -qenum=small
assuming file myprogram.c does not contain #pragma options=int statements, all enum variables within your source file will occupy the minimum amount of storage.
enum testing {ONE, TWO, THREE}; enum testing test_enum; #pragma options enum=small enum sushi {CALIF_ROLL, SALMON_ROLL, TUNA, SQUID, UNI}; enum sushi first_order = UNI; #pragma options enum=int enum music {ROCK, JAZZ, NEW_WAVE, CLASSICAL}; enum music listening_type;
using the command:
xlC yourfile.c
only the enum variable first_order will be minimum-sized (that is, enum variable first_order will only occupy 1 byte of storage). The other two enum variables test_enum and listening_type will be of type int and occupy 4 bytes of storage.
List of Batch Compiler Options and Their Defaults
Equivalent Batch Compile-Link and Incremental
Build Options