I am reading C Programming - A Modern Approach by K.N.King to learn the C programming language and it was noted that goto
statements must not skip variable-length array declarations.
But now the question is: Why are goto
jumps allowed to skip fixed-length array declarations and ordinary declarations? And more precisely, what is the behavior of examples like these, according to the C99 standard? When I tested these cases it seemed like the declarations were actually not jumped over, but is that correct? Are the variables whose declarations might have been jumped over safe to use?
1.
goto later;
int a = 4;
later:
printf("%d", a);
2.
goto later;
int a;
later:
a = 4;
printf("%d", a);
3.
goto later;
int a[4];
a[0] = 1;
later:
a[1] = 2;
for(int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
printf("%d\n", a[i]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With