Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Possible Duplicate:
How do I fix “for loop initial declaration used outside C99 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.

like image 978
fooledbyprimes Avatar asked May 04 '11 04:05

fooledbyprimes


2 Answers

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.

like image 79
Chuck Avatar answered Oct 04 '22 23:10

Chuck


You need to compile with the option -std=c99.

For example:

$ gcc -std=c99 code.c
like image 38
amillerrhodes Avatar answered Oct 04 '22 22:10

amillerrhodes