Consider this C-code, where foo
is an int
:
switch(foo){
case 1: {
int bla = 255;
case 2:
printf("case12 %d\n", bla);
break;
case 3:
printf("case3 %d\n", bla);
}
};
For different values of foo
the code gives the following output:
case12 255 # foo=1
case12 255 # foo=2
case3 0 # foo=3
I have a problem understanding foo=3
. The line that declares bla
and defines its value should not execute, when foo=3
. The switch statement should jump right to the label for case 3:
. Yet there is no warning, so bla
seems to have been declared at least. It might be used uninitialized and its value just happens to be 0
, though. Can you explain, what's happening in "case 3", and why this is legal C-code?