[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


目录
相关文章
variable `xxx' has initializer but incomplete type的解决方法
variable `xxx' has initializer but incomplete type的解决方法
387 0
|
2月前
|
关系型数据库 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
103 1
|
7月前
|
存储
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
175 0
|
JavaScript
Uncaught runtime errors: × ERROR Avoided redundant navigation to current location: “/xxx“.
Uncaught runtime errors: × ERROR Avoided redundant navigation to current location: “/xxx“.
196 0
|
数据安全/隐私保护
Do Sync Disk 0 Part 0 Failed, code=S3_F42, msg=Sync Failed after retry 5 times
Do Sync Disk 0 Part 0 Failed, code=S3_F42, msg=Sync Failed after retry 5 times
199 1
|
算法 Java
22-大厂面试题:Con-current Mode Failure如何导致以及解决
上文我们已经介绍了CMS垃圾收集器的工作原理以及流程,本篇我们接着深入说明CMS垃圾收集器的缺点以及所导致的一些问题应该如何解决。
282 0
|
程序员 Go API
译|Don’t just check errors, handle them gracefully(一)
译|Don’t just check errors, handle them gracefully
84 0
|
Java Go API
译|Don’t just check errors, handle them gracefully(二)
译|Don’t just check errors, handle them gracefully(二)
101 0
|
Java Android开发
is not allowed for source level below 1.7 的解决办法
is not allowed for source level below 1.7 的解决办法
208 0
|
C语言
解决Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
892 0
解决Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode