SLAU132V October 2004 – February 2020
An enum type is represented by an underlying integer type. The size of the integer type and whether it is signed is based on the range of values of the enumerated constants.
In strict C89/C99/C11 mode, the compiler allows only enumeration constants with values that will fit in "int" or "unsigned int".
For C++ and relaxed C89/C99/C11, the compiler allows enumeration constants up to the largest integral type (64 bits). The default, which is recommended, is for the underlying type to be the first type in the following list in which all the enumerated constant values can be represented: int, unsigned int, long, unsigned long, long long, unsigned long long.
If you use the --small_enum option, the smallest possible byte size for the enumeration type is used. The underlying type is the first type in the following list in which all the enumerated constant values can be represented: signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long.
The following example uses 8 bits instead of 16 bits when the --small_enum option is used.
enum example_enum {
first = -128,
second = 0,
third = 127
};
NOTE
Do not link object files compiled with the --small_enum option with object files that were compiled without it. If you use the --small_enum option, you must use it with all of your C/C++ files; otherwise, you will encounter errors that cannot be detected until run time.