3 ms·
Of all the things I learned in kindergarten this was my favourite :) In all seriousness, this is.. interesting! I had no idea you could have a case inside defa
by mcintyre1994 10y ago
Of all the things I learned in kindergarten this was my favourite :)
In all seriousness, this is.. interesting! I had no idea you could have a case inside default like that.
- pdpi 10y agoIt's not "inside" the default, as such. I'm not a C expert but, near as I can tell, the labels for a switch statement don't need to occur all be at the same level within the control flow inside the switch body. See my other post here about Duff's Device as another neat example of exploiting this.
- to3m 10y agoBut there is no "inside": case and default are like (slightly restricted) goto labels. They mark a place in the code, nothing more, and, as with goto labels, they can be inside nested scopes. That's why you need the "break" to explicitly leave the switch - because when execution reaches a label, it just continues. The label is a marker, nothing more. (In terms of restrictions: case/default have to be inside the switch statement somewhere, and not inside some additional switch statement nested within it. But aside from that, as demonstrated by the article, you have a good deal of freedom about where they go.)
- mcintyre1994 10y agoThis was a really helpful explanation, thankyou :)