While I'm aware this is valid C not to differentiate between enum types.
GCC does have -Wenum-compare
(which I'm using) and works as expected.
I tried using -Wconversion
but this doesn't make any difference.
How can assignments and arithmetic operators ( +
/ -
/ &
/ |
... etc) also generate warnings? (assignment, or and... etc)
{
enum Foo f = SOME_VALUE;
enum Bar b = SOME_OTHER_VALUE;
if (f != b) {
/* this warns! */
}
f = b; /* <-- how to warn about this? */
f |= b; /* .. and this? */
}
Notes:
According to this answer , only clang supports the desired behavior.
There are some approaches to emulate strongly typed enums in C, but they seem to have various limitations.
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.