Linux – GCC error: ‘for’ loop initial declaration used outside C99 mode

gcclinuxmakefile

I'm getting error: 'for' loop initial declaration used outside C99 mode when I try to compile with make. I found a 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?

Best Answer

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++) 
{

}
Related Topic