[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


目录
打赏
0
0
0
0
7
分享
相关文章
Error loading saved preferences: ~/.vuerc may be corrupted or have syntax errors. Please fix/delete
Error loading saved preferences: ~/.vuerc may be corrupted or have syntax errors. Please fix/delete
|
11月前
|
Fatal error_ ENOSPC_ System limit for number of file watchers reached, watch '...path...'
Fatal error_ ENOSPC_ System limit for number of file watchers reached, watch '...path...'
86 0
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule
255 0
什么是fail-fast和fail-safe?
本章讲解了什么是fail-fast和fail-safe,以及如何解决
186 0
22-大厂面试题:Con-current Mode Failure如何导致以及解决
上文我们已经介绍了CMS垃圾收集器的工作原理以及流程,本篇我们接着深入说明CMS垃圾收集器的缺点以及所导致的一些问题应该如何解决。
330 0
译|Don’t just check errors, handle them gracefully(二)
译|Don’t just check errors, handle them gracefully(二)
141 0
译|Don’t just check errors, handle them gracefully(一)
译|Don’t just check errors, handle them gracefully
98 0
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
1321 0
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
解决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
1001 0
解决Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等