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

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either! We adhere to an adapted version of the TootCat Code of Conduct and follow the Toot Café list of blocked instances. Ash is the admin and is supported by Fuzzface, Brian!, and Daniel Glus as moderators. Hosting costs are largely covered by our generous supporters on Patreon – thanks for all the help!