This is a quirk of C. grammar. The label ( Cleanup: cannot appear immediately before the declaration (for example, char *str ...; ), only before the statement ( printf(...); ). This wasn’t a big deal in C89, because ads could only appear at the very beginning of the block, so you can always put a shortcut a bit and avoid the problem. In C99, you can mix ads and code, but you still can't put a shortcut immediately before the ad.
You can put a semicolon immediately after the colon colon (as suggested by Renan) to make an empty expression there; this is what i would do in machine code. Also, raise the ad at the top of the function:
int main (void) { char *str; printf("Hello "); goto Cleanup; Cleanup: str = "World\n"; printf("%s\n", str); return 0; }
zwol Aug 28 '13 at 19:16 2013-08-28 19:16
source share