3 ms·
My 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.
by Someone 12y ago
My 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.