2006/3/1, Ronald G Minnich <[email protected]>: > Brantley Coile wrote: > >>now means > >> > >> { int i; for(i=0; i<10; i++); } > > > > > > Does that mean the following will compile? > > > > void > > f(void) > > { > > i = 3; > > put(i); > > for (int i = 0; i < 3; i++) > > put(i); > > if (i == 4) put(4); > > } > > > > cat > t.c > void > f(void) > { > i = 3; > put(i); > for (int i = 0; i < 3; i++) > put(i); > if (i == 4) put(4); > } > [EMAIL PROTECTED] tmp]$ cc t.c > t.c: In function 'f': > t.c:4: error: 'i' undeclared (first use in this function) > t.c:4: error: (Each undeclared identifier is reported only once > t.c:4: error: for each function it appears in.) > t.c:6: error: 'for' loop initial declaration used outside C99 mode > [EMAIL PROTECTED] tmp]$ > > > ron
And the reason it doesn't is because in this code snippet, the variable i is undeclared. I assume since the i is not declared, the compiler steps out of C99 mode and refuses to allow the C99 construct of for (int i...) --Devon
