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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With