Would this be legal code or breaking any rules?
switch (expr)
{
do
{
case 6:
/*...*/
if (/*...*/)
break;
case 7:
/*...*/
} while (0);
case 9:
/*...*/
break;
default:
break;
}
Would this be a legal way of executing case 6 followed by case 7 but only if some conditions are met? Or would this lead into undefined behavior and lets nasal dragons come out of the switch? p.s. my Question is refering to c99.
EDIT:
What i want to do is the following: assume, case 9, has to be executed in everycase. If expr is 6, i have to execute 6, under some conditions 7 and after that 9 or if expr is 7 its 7->9 so i just want to skip 7 if some conditions are met, but i cant change the order of 6,7,9.
EDIT2:
I'm not looking for an alternative soloution, I'm just interested in the behavior of this snippet.
If a switch statement has an associated case or default label within the scope of an identifier with a variably modified type, the entire switch statement shall be within the scope of that identifier.
from ISO/IEC 9899:TC3 6.8.4.2->3
Lets me feel unsure about its behavior. But I'm not sure that would aim code like mine snippet too.