Possible Duplicate:
How do I fix “for loop initial declaration used outside C99开发者_JAVA百科 mode” GCC error?
Why must I declare a loop variable outside of the for loop statement? I am getting a gcc (MacOSX) error which reads:
error: ‘for’ loop initial declaration used outside C99 mode
If I define my loop variable outside of the loop statement then gcc stops complaining.
As the error suggests, this is because declaring a variable inside the condition of a for-loop wasn't allowed until C99, and you are using an older language standard. If you're compiling directly, use the -std=c99
flag. In Xcode, go to the "Compiler - Language" options for your target and set the Language Standard to either C99 or GNU99.
You need to compile with the option -std=c99
.
For example:
$ gcc -std=c99 code.c
精彩评论