Re:How to Get Fired Using Switch Statements and Statement Ex...
by cjfd on Thursday October 15, 2020 @01:58PM
(#24791587)
And then one puts in one too many in a case where fall through actually was the idea....
[ Parent
| on HN ]
Re:How to Get Fired Using Switch Statements and Statement Ex...
by panda88888 on Thursday October 15, 2020 @03:08PM
(#24792534)
I try to be explicit and place a comment saying fall through if it is the intended behavior. This helps to inform the next person reading the code.
Re:How to Get Fired Using Switch Statements and Statement Ex...
by acheron on Thursday October 15, 2020 @04:27PM
(#24793443)
So there was a classic bug in the game NetHack where there was indeed a comment indicating there should be a fall through. Then somebody added a new case, and the fall through now went to the wrong place. But since the comment said it was supposed to fall through, nobody reported the bug.
Re:How to Get Fired Using Switch Statements and Statement Ex...
by climb_stealth on Thursday October 15, 2020 @09:39PM
(#24796510)
There are linters that raise an error when there is a fallthrough without an explicit comment [0]. I feel like that should be a must for working with C code.
[0] I don't remember which one it actually was. Possibly something commercial for MISRA compliance.
Re:How to Get Fired Using Switch Statements and Statement Ex...
by cjfd on Friday October 16, 2020 @12:05AM
(#24797348)
Actually in C++ there is a fallthrough attribute in the language nowadays. https://en.cppreference.com/w/cpp/language/attributes/fallth...