3 ms·
One of the first nasty bugs I had to work on when I first came to Silicon Valley was stack corruption from a fall through of a switch statement. After something
by pfarnsworth 6y ago
One of the first nasty bugs I had to work on when I first came to Silicon Valley was stack corruption from a fall through of a switch statement. After something like that, you learn pretty quick to always put break lines at the end of the switch before anything else.
- cjfd 6y agoAnd then one puts in one too many in a case where fall through actually was the idea....
- panda88888 6y agoI 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.
- acheron 6y agoSo 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. https://nethackwiki.com/wiki/Yeenoghu#.22A_ludicrous_bug.22 https://nethackwiki.com/wiki/Yeenoghu#.22A_ludicrous_bug.22
- climb_stealth 6y agoThere 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.
- cjfd 6y agoActually in C++ there is a fallthrough attribute in the language nowadays. https://en.cppreference.com/w/cpp/language/attributes/fallthrough https://en.cppreference.com/w/cpp/language/attributes/fallth...