A switch
statement can be mixed with a block of code by starting the block in one case label, then having another case label within the block. The block can be pictured as spanning more than one case statement.
Section 6.8.6.1 of 4.2, paragraph 2 of the C Standard [ISO/IEC 9899:2011] says,
A goto statement shall not jump from outside If a switch statement has an associated case or default label within the scope of an identifier having with a variably modified type to inside , the entire switch statement shall be within the scope of that identifier.154)
Footnote 154 says:
That is, the declaration either precedes the switch statement, or it follows the last case or default label associated with the switch that is in the block containing the declaration.
Note that However, the standard does not disallow jumping via goto
or switch
into loops that do not involve variably modified type identifiers. Consequently, loops and other blocks can be freely intermixed with switch
statements. Unfortunately, such intermixing creates code that is, at best, confusing and unclear in what it does, which can cause undesirable behavior.
...