I am trying to compile the following code in C (armcc file.c):
typedef enum A
{
JANUARY,
FEBRUARY= 0xFFFFFFFF /* Warning seen on this line */
}A;
int main()
{
int max = 0xFFFFFFFF; /* No warning seen for this line*/
...
}
I get a warning only for the enum assignment and not for integer variable assignment though in my view no warning should be seen for both.
Warning is below:
Warning:
#66-D
: enumeration value is out of "int" rangeFEBRUARY= 0xFFFFFFFF
Am I missing something here?
Int assignment produces -1 so its technically legal. Per Arm spec enum is implemented using smallest integer type so it produces error.
Enumerations An object of type enum is implemented in the smallest integral type that contains the range of the enum. The storage type of an enum is the first of the following, according to the range of the enumerators in the enum:
Implementing enum in this way can reduce data size. The command-line option --enum_is_int forces the underlying type of enum to at least as wide as int.
User contributions licensed under CC BY-SA 3.0