(ISO C, §6.2.5) The Carbide C compiler uses the Enums Always Int and ANSI Strict settings to choose which underlying integer type to use for an enumerated type.
If you enable the Enums Always Int setting, the underlying type for enumerated data types is set to signed int. Enumerators cannot be larger than a signed int. If an enumerated constant is larger than an int, the compiler generates an error.
If you disable the ANSI Strict setting, enumerators that can be represented as an unsigned int are implicitly converted to signed int.
#pragma enumsalwaysint on
#pragma ANSI_strict on
enum foo { a=0xFFFFFFFF }; // ERROR. a is 4,294,967,295:
// too big for a signed int
#pragma ANSI_strict off
enum bar { b=0xFFFFFFFF }; // OK: b can be represented as an
// unsigned int, but is implicitly
// converted to a signed int (-1).
If you disable the Enums Always Int setting, the compiler chooses the integral data type that supports the largest enumerated constant. The type can be as small as a char or as large as a long int. It can even be a 64-bit long long value.
If all enumerators are positive, the compiler chooses the smallest unsigned integral base type that is large enough to represent all enumerators. If at least one enumerator is negative, the compiler chooses the smallest signed integral base type large enough to represent all enumerators.
#pragma enumsalwaysint off
enum { a=0,b=1 }; // base type: unsigned char
enum { c=0,d=-1 }; // base type: signed char
enum { e=0,f=128,g=-1 }; // base type: signed short
The compiler uses long long data types only if you disable Enums Always Int and enable the longlong_enums pragma. (None of the settings corresponds to the longlong_enums pragma.)
#pragma enumsalwaysint off
#pragma longlong_enums off
enum { a=0x7FFFFFFFFFFFFFFF }; // ERROR: a is too large
#pragma longlong_enums on
enum { b=0x7FFFFFFFFFFFFFFF }; // OK: base type: signed long long
enum { c=0x8000000000000000 }; // OK: base type: unsigned long long
enum {þd=-1,e=0x80000000 }; // OK: base type: signed long long
When you disable the longlong_enums pragma and enable ANSI Strict, you cannot mix unsigned 32-bit enumerators greater than 0x7FFFFFFF and negative enumerators. If you disable both the longlong_enums pragma and the ANSI Strict setting, large unsigned 32-bit enumerators are implicitly converted to signed 32-bit types.
#pragma enumsalwaysint off
#pragma longlong_enums off
#pragma ANSI_strict on
enum { a=-1,b=0xFFFFFFFF }; // error
#pragma ANSI_strict off
enum { c=-1,d=0xFFFFFFFF }; // base type: signed int (b==-1)
The Enums Always Int setting corresponds to the pragma enumsalwaysint. To check this setting, use __option (enumsalwaysint).
By default, this setting is disabled.
See also “enumsalwaysint”, “longlong_enums”, and Checking Settings.