Consider this C code, where foo- 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, the foocode gives the following result:
case12 255
case12 255
case3 0
I have a problem with understanding foo=3. A line declaring blaand defining its value should not be executed when foo=3. The switch statement should go straight to the label for case 3:. However, there is no warning, therefore bla, apparently, at least it has been announced. It can be used uninitialized, and its value, as a rule, turns out to be 0. Can you explain what happens in case 3 and why is it a legitimate C code?
source
share