Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
The end of one case is the next case or default. Easy.
C's behaviour is because whoever came up with that idea was clearly thinking in assembly. Then again, all good C programmers think in assembly anyway so that it's no big deal.
xcodesucks39390dWell, in Pascal the Case statement does not fall through and in Swift, the switch does not fall through. Actually, it kinda says something... "Safety Belts"
These are languages that are not as concerned with performance as they are concerned with safety for the junior programmer and keeping them from ripping their hair out over beginner bugs.
Stacking a bunch of cases that match a single condition... or putting some "special cases" on top of a base case to leverage the fall-through is the natural way to think when working threads or pre-emptive interrupt work.
As others have said, C thinkers think at the machine level... in assembly. Someone who writes in C stands a good chance of being very handy with a soldering iron. Someone who writes in Pascal or Swift probably could not tell you what a soldering iron looked like.
@xcodesucks GCC 7 and later has an interesting warning. If the case falls through and is not empty, a comment in certain format is required.
When upgrading GCC, I got bitten by that one in conjunction with my usual -Werror because I obviously had a comment there, but that was from long before the GCC team decided on the recognised format.
And I do have a soldering iron for doing electronics, you got me on that one. :-)
wowotek562990dthis is actually make sense if you ever programmed in Assembly, at least ARM
RememberMe806490dAh, check out pattern matching in a ML-family functional programming language like SML, OCaml, F#, or Haskell
thomasd37390dThe fall through can be very useful
Root4066190dAssembly is amazing, and case fallthrough is super useful. *nod*
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job