Through a little typo, I accidentally found this construct:
int main(void) { char foo = 'c'; switch(foo) { printf("Cant Touch This\n"); // This line is Unreachable case 'a': printf("A\n"); break; case 'b': printf("B\n"); break; case 'c': printf("C\n"); break; case 'd': printf("D\n"); break; } return 0; } It seems that the printf at the top of the switch statement is valid, but also completely unreachable.
I got a clean compile, without even a warning about unreachable code, but this seems pointless.
Should a compiler flag this as unreachable code?
Does this serve any purpose at all?
-Wswitch-unreachablegotoin and out of the otherwise unreachable part, which may be useful for various hacks.switchis just a conditionalgotowith multiple labels. There are more or less same restrictions on it's body as you would have on a regular block of code filled with goto labels.