4 ms·
What does the mentioned switch statement do?
by thisjepisje 12y ago
What does the mentioned switch statement do?
- webkike 12y agoIt is equivalent to: if (x == 1 || x == 2 || x == 3 || x == 4) printf("What the fuck?");
- Someone 12y agoMy guess would be that it triggers a compiler error because of the missing braces {}. However, reading http://en.cppreference.com/w/c/language/switch http://en.cppreference.com/w/c/language/switch and https://msdn.microsoft.com/en-us/library/66k51h7a.aspx https://msdn.microsoft.com/en-us/library/66k51h7a.aspx, I am starting to wonder about that. Both pages claim that switch(expression) can be followed by any statement, not just compound ones. That seems to make it legal C. It also would make switch(i) x += 1; and possibly even switch(i) foo: x += 1; valid (but nonsensical) C. Chances are that the standard contains special wording that prohibits the latter two, though. If not, this is useful to know for the obfuscated C contest (more so if you can jump to that label)
- webkike 12y agoIt does not, GCC compiles the example perfectly fine.