goto:[Error] jump into scope of identifier with variably modified type

C language GOTO things you don't know

Error Code

#include <stdio.h>
int main()
{
    
        
    int a=1,b=2;    
    goto End;	
    int c[b];
End:	
    return 0;
} 

Compiler error content

In function 'main':[Error] jump into scope of identifier with variably modified type
[Note] label 'End' defined here
[Note] 'c' declared here

Why does it appear

根据C11标准:
A goto statement is not allowed to jump past any declarations of objects with variably modified types. A jump within the scope, however, is permitted.

That is to say, the code between the goto statement and the "label" is not allowed to have variable-length array declaration statements. Because goto is an unconditional jump statement, the address needs to be determined at compile time. If the variable-length array is sandwiched in it, the compiler cannot determine the address.
The following codes are correct

#include <stdio.h>
int main()
{
    
        
    goto End;	
    int a=1,b=2;	
    int c[2];
End:	
    return 0;	
} 

How to deal with it

Move the definition of variable-length arrays outside the scope of "goto-tag"

#include <stdio.h>
int main()
{
    
    	
    int a=1,b=2;	
    int c[a];	
Begin:     
    goto End;
End:	
    return 0;	
} 

If you like it, just one click and three links! ! !

Guess you like

Origin blog.csdn.net/qq_31985307/article/details/114128410