According to the C Standard, subclause 6.8.4.2, paragraph 4 [ISO/IEC 9899:2011],
...
If a programmer declares variables, initializes them before the first case statement, and then tries to use them inside any of the case statements, those variables will have scope inside the switch block but will not be initialized and will consequently contain garbage indeterminate values.
Noncompliant Code Example
...
Using test conditions or initializing variables before the first case statement in a switch block can result in unexpected behavior because that code will not be executedand undefined behavior.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
DCL41-C | Medium | Unlikely | Medium | P4 | L3 |
...
Bibliography
| [ISO/IEC 9899:2011] | Subclause 6.8.4.2, "The switch Statement" |
...