Description
The #pragma enum directive specifies the size of enum variables that follow. The size at the left brace of a declaration is the one that affects that declaration, regardless of whether further enum directives occur within the declaration. This pragma pushes a value on a stack each time it is used, with a reset option available to return to the previously pushed value.
Syntax
where option can be substituted with one of the following:
| Options | |
| small | enum size is the smallest integral type that can contain all variables. |
| int | enum size is 4 |
| 1 | enum size is 1 |
| 2 | enum size is 2 |
| 4 | enum size is 4 |
| pop | the option will reset the enum size to the one before the previously set enum size. |
| reset | the option is an alternative method of resetting the enum size to the one before the previously set enum size. This option is provided for backwards compatibility. |
Example:
#pragma enum(1) #pragma enum(2) #pragma enum(4) #pragma enum(pop) /* will reset enum size to 2 */ #pragma enum(reset) /* will reset enum size to 1 */ #pragma enum(pop) /* will reset enum size to default
Popping on an empty stack generates a warning message and the enum value remains unchanged.
The gen(enumsize) option can be used to set the enum size to default. The #pragma enum directive overrides gen(enumsize).
![]()
Preprocessor Directives - An
Overview
Preprocessor Directive -
#pragma
![]()
enumsize code
generation option - gen(enumsize) option
