Variable declaration after goto Label

前端 未结 7 2257
我在风中等你
我在风中等你 2020-12-04 15:20

Today I found one interesting thing. I didn\'t know that one can\'t declare a variable after a goto label.

Compiling the following code

#include <         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 15:48

    You want a semi-colon after the label like this:

     #include 
     int main() {
         int x = 5;
         goto JUMP;
         printf("x is : %d\n",x);
     JUMP: ;     /// semicolon for empty statement
         int a = 0; 
         printf("%d",a);
     }    
    

    Then your code compiles correctly for the C99 standard, with gcc -Wall -std=c99 -c krishna.c (I'm using GCC 4.6 on Debian/Sid/AMD64).

提交回复
热议问题