Unfortunately, the ISO C standard (c99 6.4.4.3) indicates that enum constants are of type int . If you compile the above, for example. gcc -W -std=c89 -pedantic , it issues an ISO C restricts enumerator values to range of 'int' [-pedantic] warning ISO C restricts enumerator values to range of 'int' [-pedantic] . Some built-in compilers may not accept code at all.
If your compiler has a sorter, you can work around the problem using
typedef enum hardware_register_e { REGISTER_STATUS_BIT = -2147483648 } hardware_register_t;
but it works correctly only if int is 32-bit two types of additions in your architecture. These are all 32-bit and 64-bit architectures that I have ever used or heard.
Edited to add: ARM7 uses a 32-bit two-component int type, so the above should work fine. I recommend that you leave a comment explaining that the actual value is 1<<31 . You never know if anyone is closing code or using another compiler. If the new compiler issues a warning, the comment on the same line should make it trivial to fix it. Personally, I would have wrapped the code conditional, perhaps
typedef enum hardware_register_e { #ifdef __ICCARM__ REGISTER_STATUS_BIT = -2147483648 #else REGISTER_STATUS_BIT = 1 << 31 #endif } hardware_register_t;
Nominal animal
source share