[Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode 解决方法

简介: [Error] ‘for’ loop initial declarations are only allowed in C99 or C11 mode[Note] use option -std=c99,-std=gnu99,-std=c11 or-std=gnu11 to compile your code

一、异常


编写C语言程序遇到如下异常,不能成功编译运行程序

使用 GCC 编译代码是报出

[Error] ‘for’ loop initial declarations are only allowed in C99 or C11 mode

[Note] use option -std=c99,-std=gnu99,-std=c11 or-std=gnu11 to compile your code


二、解决方法


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


这种写法在 GCC 中是错误的,必须先定义变量i,然后可以成功编译运行。


也可以将 GCC 换成 C99 标准就可以在 for 循环内定义 i 变量了。


gcc src.c -std=c99 -o src


目录
相关文章
|
27天前
|
关系型数据库 MySQL Linux
Packet for query is too large (4467936 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable
【10月更文挑战第15天】解决Packet for query is too large (4467936 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable
43 1
Flutter之运行提示Could not update files on device: Connection closed before full header was received
Flutter之运行提示Could not update files on device: Connection closed before full header was received
752 0
|
5月前
|
Java
【ERROR】‘<>‘ operator is not allowed for source level below 1.7
【ERROR】‘<>‘ operator is not allowed for source level below 1.7
50 0
|
6月前
|
存储
tracker_query_storage fail, error no: 28, error info: No space left on device
tracker_query_storage fail, error no: 28, error info: No space left on device
153 0
|
6月前
|
测试技术
Could not proxy command to the remote server. Original error: timeout of 240000ms exceeded 的解决办法
Could not proxy command to the remote server. Original error: timeout of 240000ms exceeded 的解决办法
237 0
|
算法 Java
22-大厂面试题:Con-current Mode Failure如何导致以及解决
上文我们已经介绍了CMS垃圾收集器的工作原理以及流程,本篇我们接着深入说明CMS垃圾收集器的缺点以及所导致的一些问题应该如何解决。
261 0
error: statement with no effect [-Werror=unused-value]
error: statement with no effect [-Werror=unused-value]
220 0
飞思卡尔codewarrior下载出现USBD connection error:Failed to connect to targe(Reason :Target reset pin time out)
飞思卡尔codewarrior下载出现USBD connection error:Failed to connect to targe(Reason :Target reset pin time out)
飞思卡尔codewarrior下载出现USBD connection error:Failed to connect to targe(Reason :Target reset pin time out)
解决办法:RuntimeError: dictionary changed size during iteration
解决办法:RuntimeError: dictionary changed size during iteration
133 0
|
Java Android开发
is not allowed for source level below 1.7 的解决办法
is not allowed for source level below 1.7 的解决办法
185 0