开发者

‘for’ loop initial declaration used outside C99 mode [duplicate]

开发者 https://www.devze.com 2023-03-02 11:32 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do I fix “for loop initial declaration used outside C99开发者_JAVA百科 mode” GCC error?
This question already has answers here: Closed 11 years ago.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消