int main() {
int sz = 10;
goto end;
char bytes[sz];
end:
return 0;
}
I get the following error at compilation. I use gcc with C99 standard.
test.c: In function ‘main’:
test.c:3:2: error: jump into scope of identifier with variably modified type
test.c:5:1: note: label ‘end’ defined here
test.c:4:7: note: ‘bytes’ declared here
It is forbidden by the standard:
C99 standard, paragraph 6.8.6.1 Constraints [...] A goto statement shall not jump from outside the scope of an identifier having a variably modified type to inside the scope of that identifier.
Your goto
skips the line that allocates your bytes
array at runtime. That is not allowed.
You could limit the scope of bytes
by surrounding it with curly braces, put the allocation before the goto
and label, or not use goto
at all.
To put it more plainly, once bytes
is allocated, you are now "inside" the scope. Before the allocation, you are "outside" the scope. So you can't "jump from outside the scope" to "inside the scope".
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