GCC错误:在C99模式之外使用了'for'循环初始声明 [英] GCC error: 'for' loop initial declaration used outside C99 mode
问题描述
当我尝试使用make
进行编译时,我得到了error: 'for' loop initial declaration used outside C99 mode
.我发现了一个 Wiki 说
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
在编译行中放入-std = c99:
gcc -std=c99 foo.c -o foo
问题是我不知道如何在make
中指定它.我打开了 Makefile ,找到了CC = gcc
并将其更改为CC = gcc -std=c99
,但没有结果.有什么想法吗?
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?
推荐答案
将CFLAGS = -std = c99放在Makefile的顶部.
Put CFLAGS=-std=c99 at the top of your Makefile.
要在不使用C99的情况下消除错误,只需在for循环位于其中的块顶部声明迭代器变量即可.
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.
代替:
for (int i = 0; i < count; i++)
{
}
使用:
int i;
//other code
for (i = 0; i < count; i++)
{
}
这篇关于GCC错误:在C99模式之外使用了'for'循环初始声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!