您的位置:首页 > 运维架构

codeblocks gcc error: 'for' loop initial declarations are only allowed in C99 mode|

2015-03-14 22:38 471 查看
源代码

#include <stdio.h>
#include <stdlib.h>

int main()
{
    for(int i=0; i<1600; i=i+20)
    {
        int c;
        c = 5*(i-32)/9;
        printf("%d \t %d\n",i,c);
    }
    return 0;
}
使用gcc编译代码是报出

error: 'for' loop initial declarations are only allowed in C99 mode

note: use option -std=c99 or -std=gnu99 to compile your code

错误,这是因为在gcc中直接在for循环中初始化了增量:

for(int i=0; i<len; i++) {  
}
这语法在gcc中是错误的,必须先先定义i变量:

int i;
for(i=0;i<len;i++){
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐