错误:'for'循环初始声明只允许在C99模式 [英] error: ‘for’ loop initial declarations are only allowed in C99 mode

查看:1340
本文介绍了错误:'for'循环初始声明只允许在C99模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到下面的错误,什么是性病= C99 / STD = gnu99模式?

源$ C ​​$ C:

 的#include<&stdio.h中GT;空隙FUNCT(中间体[5]);诠释的main()
{
    INT编曲[5] = {1,2,3,4,5};
    FUNCT(ARR);
    为(中间体J = 0; J&小于5; J ++)
    的printf(%d个,编曲[J]);
}空隙FUNCT(中间体P [5]){
        INT I,J;
        对于(i = 6,J = 0; I< 11;我++,J ++)
            P [J] =我;
}
错误信息:
hello.c中:在函数'主':
的hello.c:11:2:错误:'for'循环初始声明只允许在C99模式
为(中间体J = 0; J&小于5; J ++)
      ^
的hello.c:11:2:注意:使用选项-std = C99或-std = gnu99来编译code`


解决方案

这是因为声明内变量循环无效C,直到C99(这是C的1999年出版的标准),你可以宣布你外面的柜台为他人指出或使用-std = C99标志明确地告诉编译器您正在使用这个标准,它应该跨preT它是这样。

I am getting the below error, what is std=c99/std=gnu99 mode?

source Code:

#include <stdio.h>

void funct(int[5]);

int main() 
{        
    int Arr[5]={1,2,3,4,5};
    funct(Arr);
    for(int j=0;j<5;j++)
    printf("%d",Arr[j]);
}

void funct(int p[5]) {
        int i,j;
        for(i=6,j=0;i<11;i++,j++)
            p[j]=i;
}


Error Message:
hello.c: In function ‘main’:
hello.c:11:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
for(int j=0;j<5;j++)
      ^
hello.c:11:2: note: use option -std=c99 or -std=gnu99 to compile your code`

解决方案

This happens because declaring variables inside a for loop wasn't valid C until C99(which is the standard of C published in 1999), you can either declare your counter outside the for as pointed out by others or use the -std=c99 flag to tell the compiler explicitly that you're using this standard and it should interpret it as such.

这篇关于错误:'for'循环初始声明只允许在C99模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆