C considered dangerous
C considered dangerous
Posted Sep 11, 2018 16:53 UTC (Tue) by DHR (guest, #81356)Parent article: C considered dangerous
A declaration does not have to be reached unless it has an initializer (or is a VLA). So these would probably be correct C, and perhaps meaningful.
Any executable code between a switch head and the first case label (or other label) is unreachable and a good compiler should flag it. Adding an auto-initializer carelessly triggers this problem.
If a declaration in the switch body (and not further nested) has a scope covering the rest of the switch body. So all cases.
The unfortunate choice of -Wdeclaration-after-statement means that placing a declaration at the start of a switch body is sometimes a good choice.
A compiler should flag any unused variable.
