News for hackers. Stuff that matters.
Re:Ask HN: What one change in C would make it a better langu... by didgetmaster on Thursday July 27, 2023 @11:46AM (#36895358)
The default behavior for a case within a switch statement should be to break. If you want to fall through to the next case, it should have been an explicit command (e.g. fallthrough).

switch(x) { case 1: DoSomething(); case 2: DoSomethingElse(); case 3: SomePrep(); fallthrough; case 4: DoMore(); default: DoNothing; }

Only one statement needed to have case 3 fall through to case 4. No breaks needed at the end of any other cases.

There are no comments on this comment yet.