在用 Eclipse CDT 编写c程序时出现 `for' loop initial declaration used outside C99 mode 错误是因为加 -std=c99 选项
C99标准支持下面这种for 循环的变量i的定义及初始化方式:
for (int i=1; i<10; i++)
{
printf("Hello C!");
}
C99标准之外的C标准支持下面这种for 循环的变量i的定义及初始化方式:
int i=1;
for (i=1; i<10; i++)
{
printf("Hello C!");
}
解决办法:
右键点击项目->Properties->C/C++ Build -> Settings -> Tool Settings -> GCC C Complier -> Miscellaneous
在 "Other flags" 中追加 -std=c99