for (int i = 0; ...)
is the syntax that was introduced in C99. To use it, you must enable C99 mode by passing -std=c99 (or some later standard) to GCC. C89 Version:
int i; for (i = 0; ...)
EDIT
Historically, C has always forced programmers to declare all variables at the beginning of a block. So something like:
{ printf("%d", 42); int c = 43;
need to rewrite as:
{ int c = 43; printf("%d", 42);
a block is defined as:
block := '{' declarations statements '}'
C99, C ++, C #, and Java allow variable declarations anywhere in the block.
The real reason (guessing) is the distribution of internal structures (for example, calculating the stack size) of the ASAP when analyzing the source C, without going to another compiler pass.
dfa Aug 17 '09 at 13:08 2009-08-17 13:08
source share