3 ms·
Surely the following would work just as well? #define brkcase break;case kinda defeats the purpose of the macro even.
by leni536 2y ago
Surely the following would work just as well?
#define brkcase break;case
kinda defeats the purpose of the macro even.
- MaxBarraclough 2y agoThat strikes me as better. The original macro presumably misbehaves if there's more than one statement in a sequence, as the if will only affect the first statement.
- wrsh07 2y agoI think the behavior is slightly different since this one breaks the above case, and the other one only omits its case from fallthrough Incidentally, what happens if you use your brkcase as the first case? I don't find either particularly exciting - a macro that would append break to the current case feels better
- leni536 2y agoBoth version of the macro makes this fall through from 0: switch (a) { brkcase 0: foo(); case 1: bar(); } so in a sense the `if (0) case` trick also affects the previous case, not the current one. But that one also falls apart when there are multiple statements under the brkcase.