temp.c: In function ‘main’:
temp.c:7: error: expected expression before ‘int’
temp.c:8: error: ‘a’ undeclared (first use in this function)
temp.c:8: error: (Each undeclared identifier is reported only once
temp.c:8: error: for each function it appears in.)

Now what is the logic behind that? I heard that one cannot create variables inside the case statements of switch. Since JUMP is inside the same scope (the scope of main function, in my case) of the goto statement, I believe that scope is not an issue here. But then, why am I getting this error?

sorry about that..Changed to JUMP so that there is no confusion..And please consider this as an easy test program which reproduce what I am asking here..Those printf statements mean nothing.
–
KrishnabhadraDec 5 '11 at 11:17

You all are saying, 1) A label needs to be a part of a statement. And in C a declaration is not a statement. 2) The error is nothing related with scope (which is what I first thought), correct?
–
KrishnabhadraDec 5 '11 at 11:36

Yes, most likely. There may be different problems with bypassing variable initialization due to the jump, but you should get a decent diagnostic for that. And if you do, just separate declaration and initialization.
–
Michael Krelin - hackerDec 5 '11 at 11:41

It's not because of the label per se, it's because there are already statements (goto and printf). The latest standard seems to allow variable declarations in arbitrary places, but not every compiler fully conforms to the standard. Also, identifiers are case-sensitive in C and your label must be the same in both places.

#include <stdio.h>
int main() {
int x = 5;
goto JUMP;
printf("x is : %d\n",x);
JUMP:
printf("Do anything after label but dont declare
anything. even empty statement will also work
because label can only be part of a statement");
int a = 0;
printf("%d",a);
}

Simple explanation, other than the spec says not, is that the compiler is exepecting the code after the goto to be something that compiles into an operation which it can then calculate the offset of, and is kicking because your variable declaration isn't a statement/block that it can compile into such an offset.