ANSI C89 requires variables to be declared at the beginning of a scope. It relaxes on the C99.
This is clear when using gcc , when you use the -pedantic flag, which more strictly abides by the standard rules (since it is used by default for C89 mode).
Please note that this is really C89 code:
include <stdio.h> int main() { int i = 22; printf("%d\n", i); { int j = 42; printf("%d\n", j); } return 0; }
But the use of braces to indicate the scope (and, therefore, the lifetime of variables in this area) does not seem particularly popular, therefore C99 ... etc.
source share