简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM