Issue
I'm getting error: 'for' loop initial declaration used outside C99 mode
when I try to compile with make
. I found a href="http://cplusplus.syntaxerrors.info/index.php?title=%27for%27_loop_initial_declaration_used_outside_C99_mode" rel="nofollow">wiki that says
Put -std=c99 in the compilation line:
gcc -std=c99 foo.c -o foo
Problem is I don't know how to specify this in make
. I opened Makefile, found CC = gcc
and changed it to CC = gcc -std=c99
with no results. Any ideas?
Solution
Put CFLAGS=-std=c99 at the top of your Makefile.
To remove the error without using C99, you just need to declare your iterator variable at the top of the block the for loop is inside.
Instead of:
for (int i = 0; i < count; i++)
{
}
Use:
int i;
//other code
for (i = 0; i < count; i++)
{
}
Answered By - Todd Branchflower Answer Checked By - Dawn Plyler (WPSolving Volunteer)