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

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

使用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循环中初始化了增量:

[cpp] view
plain
copy

  1. for(int i=0; i<len; i++) {
  2. }

这语法在gcc中是错误的,必须先先定义i变量:

[cpp] view
plain
copy

  1. int i;
  2. for(i=0;i<len;i++){
  3. }

这是因为gcc基于c89标准,换成C99标准就可以在for循环内定义i变量了:

gcc src.c -std=c99 -o src

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

时间: 2024-08-05 11:14:59

error: 'for' loop initial declarations are only allowed in C99 mode的相关文章

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

在gcc中,写了这样几句代码 for(int i=1; i<=2; i++) { if(*e >= T[i]) { *e = T[i]; } } 这种for循环的写法在gcc中不支持,得现在for循环之前对i进行i定义,然后在使用 如果非得这么写的话在gcc进行编译的时候可以加上如下选项 note: use option -std=c99 or -std=gnu99 to compile your code

‘for’ loop initial declarations are only allowed in C99 mode

#include <stdio.h>int main(){ for(int i=0;i<10;i++){ printf("\n%d",i); } return 0;} linux 使用 gcc 进行编译时报 ‘for’ loop initial declarations are only allowed in C99 mode 原因是要在 for() 外面 初始化 i 变量 #include <stdio.h>int main(){ int i = 0;

&#39;for&#39; loop initial declarations are only allo

linux系统下的c编程与windows有所不同,如果你在用gcc编译代码的时候提示‘for’ loop initial declarations are only allowed in C99 mode,可能就是因为你在loop循环比如for中使用未预先定义的变量,比如: for(int i=0;i<10;i++) { } 这种写法在vc里是没有错的,而子gcc就会提示错误,要求遵守c89标准,c89标准是不支持上述写法的.如果你非要这么写可以这样编译,使用c99标准: gcc helo.c

Flex builder经常会抛出:进程已终止,没有建立到调试器的连接。error while loading initial content的解决方法

不争气的adobe啊,在经过乔帮主与HTML5的打压,导致了现在好多的AS3程序员都转行了.虽然想抓住移动时代,但是却在性能上不敢恭维.虽然如此但是也促使了,好多AS3开发者拓展自己,甚至通过使用工具把AS3项目转化为html5项目.确实在国内有几家做的比较好的公司:layabox,Egret.仿佛给flash页游开发带来了新生.... 今天在看以前的东西时出现了一个问题,程序在运行的时候总是会抛出错误,错误如下: 进程已终止,没有建立到调试器的连接. error while loading i

error in Swift. “Consecutive Declarations On A Line Must Be Separated By &#39;;&#39;”

当输入的时候以上代码的时候出现这个错误,经过尝试发现条件表达式?前面应该有一个空格  不然会和swift中的?和 !混淆 error in Swift. "Consecutive Declarations On A Line Must Be Separated By ';'"

ERROR 1130 (HY000): Host &#39;test177&#39; is not allowed to connect to this MySQL server

异常 在测试环境新搭建的MySQL服务端,启动后登陆MySQL如下异常: [[email protected] ~]# mysql -u root -po2jSLWw0ni -h test177 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1130 (HY000): Host 'test177' is not allowed to connect to this My

Termux源码导入遇到的问题

今天看到一个有意思的项目--Termux,然后就把源码搞下来了.但是导入到Android Studio里编译运行的时候报错了! java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.termux/files/instant-run/dex/slice-support-a

for循环中i变量初始化时报错

用的gcc版本号为:gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 写的程序源文件名为:643b.c, 该文件中,有一个语句:for(int i=0;i<11;i++) 运行编译命令:gcc -o 643b 643b.c 会报错: 643b.c: In function 'main': 643b.c:5:2: error: 'for' loop initial declarations are only allowed in C99 mode for(int

libjson-c库的使用问题备忘

 gcc -o json-demo -g json-demo.c -std=c99 -I/usr/include/json -L/usr/lib/i386-linux-gnu/ -ljson 注意: 1.json-demo和json-demo.c参数需要在前面,不能在后面,见错误1 2.需要就爱如-std=c99,代码中需要,也可以用-std=gnu99,见错误2 3.-I是json的头文件的路径 4.-L是json库所在位置,这个路径可能根据系统不同而不同,建议用find / -name