3 ms·
As a side note, traditional enum completeness checking in C is broken, in that you can only choose either to be warned statically when you need to add a new cas
by dllthomas 13y ago
As a side note, traditional enum completeness checking in C is broken, in that you can only choose either to be warned statically when you need to add a new case (no default case) or to handle things at runtime if you get something unexpected (a default case).
Fairly recent gcc (last few years) now has a -Wswitch-enum flag which says "warn me even when there is a default label" which is the safest option (I assume clang has something similar though I haven't actually checked).
- nhaehnle 13y agoThis option is also really annoying when you have switches over really large enum types, such as key codes, where it is usually legitimate to have a default case. I guess even more annotations are needed ;)
- dllthomas 13y agoHeh, doubtless. If you have a switch statement where adding a case to the enum doesn't mean you need to consider whether to add it to that switch, it sounds like an appropriate place to use pragmas to disable the warning for the one switch (http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html). If you do need to consider that switch, then I'd say you should still suck it up and list every case (though possibly collapsing similar groups of cases into a single macro... "#define NUMERIC_KEYS case KEY_KP0: case KEY_KP1"...).
- pjmlp 13y agoLots of things in C are broken, not only enums.
- dllthomas 13y agoThanks.