TIL that in the C `switch` statement, the `default` clause doesn't have to be the last one. (It still runs when no other options match including ones declared below it.)

@bugaevc hah, yeah! C's switch has so many surprises...

@bugaevc And that can change semantics because of fallthrough, right?

@hirnbrot @bugaevc Yep. Nice if you want to keep cases sorted but then there's an “also relevant in case of anything unrecognized” in the middle:

case A: … break;
case B: … break;
case C: … break;

If you drop down a level, they're basically value-labeled goto targets and the switch is basically a branch table, which is congruent with the syntax (and sometimes with the output!), and is also “why” “fallthrough” is a thing in the first place: the labels aren't blocks.

@bugaevc That's both insane and potentially useful. :)

Sign in to participate in the conversation
Mastodon for Tech Folks

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!