-qenum

Category

Floating-point and integer control

Pragma equivalent

#pragma options enum, #pragma enum

Purpose

Specifies the amount of storage occupied by enumerations.

Syntax

Read syntax diagramSkip visual syntax diagram
Option syntax

                 .-intlong-.   
>>- -q--enum--=--+-int-----+-----------------------------------><
                 +-small---+   
                 +-1-------+   
                 +-2-------+   
                 +-4-------+   
                 '-8-------'   

Read syntax diagramSkip visual syntax diagram
Pragma syntax

                         .-intlong-.        
>>-#--pragma--enum----(--+-int-----+--)------------------------><
                         +-small---+        
                         +-1-------+        
                         +-2-------+        
                         +-4-------+        
                         +-8-------+        
                         +-pop-----+        
                         '-reset---'        

Defaults

-qenum=intlong

Parameters

1
Specifies that enumerations occupy 1 byte of storage, are of type signed 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. Values cannot exceed the range of signed int.
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 of type int.
intlong
Specifies that enumerations occupy 8 bytes of storage, as with the 8 suboption, if the range of values in the enumeration cannot be represented by one of int or unsigned int. Otherwise, the enumerations occupy 4 bytes of storage as with the 4 suboption.
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. Signedness 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.
pop | reset (pragma only)
Discards the current pragma setting and reverts to the setting specified by the previous pragma directive. If no previous pragma was specified, reverts to the command-line or default option setting.

Usage

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.

Table 1. Enumeration sizes and types
  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
Notes:
  • These enumerations are too large for the -qenum=1|2|4|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:
    • If -qenum=int is in effect, a severe error message is issued and compilation stops.
    • For all other settings of -qenum, an informational message is issued and compilation continues.

The #pragma enum directive must 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.

Examples

If the following fragment is compiled with the enum=small option:
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.
If the following fragment is compiled with the enum=small option:
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.
The following code segment generates a warning and the second occurrence of the enum pragma is ignored:
#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 */

Predefined macros

None.