The enumeration constant ( val1 in your example) must be of type int according to the C standard. This is a signed type and a 32-bit system, the value FFFFFFFF will not fit into it. Thus, this value will be converted to a signed integer in a specific concrete variant (specific to the compiler). If this is not done, you will get a signal defined by the implementation.
Writing code that relies on this is bad because it is not portable and unpredictable. There is no compiler setting that can fix this, because it is a language design.
I believe the gcc -pedantic / -pedantic-errors flag can be removed to get rid of the warning, but this is a bad idea since you will no longer follow the default C. gcc standard, the non-standard "skunk mode" -std=gnu90 or -std=gnu11 will compile code like any -std=cxx without -pedantic-errors .
This is why enumerations are unsuitable for any form of bitmasks or bitwise operations.
The best solution is to get rid of the enumeration and use either #define or const uint32_t , depending on what is most convenient for your specific scenario.
source share