有没有什么方法可以在 gcc 中启用 for(int i=0; ... 而不必打开 c99 模式
我有一个非常大的程序,它用 gcc 编译而没有警告。
如果我在命令行上打开 c99 模式 --std=c99 ,它会给出大量警告和错误。
但我喜欢用 for(int i=0; i<20; i++){ code }
代替 {int i; for (i=0; i<20; i++){ code }}
有没有办法告诉 gcc 允许这个并且只允许这个?
或者,有什么方法可以在我正在处理的特定功能中启用 c99 模式吗?像这样的东西
#pragma c99 on
for(int i=0; i<99; i++)
{
code
}
#pragma c99 off
I've got a very big program which compiles with gcc without warnings.
If I turn on c99 mode --std=c99 on the command line, it gives a huge number of warnings and errors.
But I love the idiom for(int i=0; i<20; i++){ code }
in place of {int i; for (i=0; i<20; i++){ code }}
Is there any way to tell gcc to allow this and only this?
Alternatively, is there any way to enable c99 mode in the particular functions I'm working on? Something like
#pragma c99 on
for(int i=0; i<99; i++)
{
code
}
#pragma c99 off
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
警告和错误很可能是因为
-std=c99
请求符合标准的 C99,这意味着未定义许多污染 C99 命名空间的特定于平台的函数。相反,您应该尝试
--std=gnu99
,它是相当于gnu89
默认模式的 C99。It is likely that the warnings and errors are because
-std=c99
requests standard-conforming C99, which means that many platform-specific functions that pollute the C99 namespace are not defined.Instead, you should try
--std=gnu99
, which is the C99-equivalent to the default mode ofgnu89
.或者使用-std=gnu99,您可以禁用单个警告:
阅读info gcc:
Alternatively to use -std=gnu99 you can disable individual warnings:
Read info gcc: