Why does ARM treat "0xFFFFFFFF" as out of "int" range for enums but not for assignment?

4

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" range FEBRUARY= 0xFFFFFFFF

Am I missing something here?

c
armcc
asked on Stack Overflow Jul 18, 2018 by Quest • edited Jul 18, 2018 by pushkin

1 Answer

1

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:

  • unsigned char if not using --enum_is_int
  • signed char if not using --enum_is_int
  • unsigned short if not using --enum_is_int
  • signed short if not using --enum_is_int
  • signed int
  • unsigned int except C with --strict
  • signed long long except C with --strict
  • unsigned long long except C with --strict.

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.

answered on Stack Overflow Jan 13, 2019 by sbh

User contributions licensed under CC BY-SA 3.0