有没有什么方法可以在 gcc 中启用 for(int i=0; ... 而不必打开 c99 模式

发布于 2025-01-03 00:29:17 字数 391 浏览 5 评论 0原文

我有一个非常大的程序,它用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微暖i 2025-01-10 00:29:17

警告和错误很可能是因为 -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 of gnu89.

风吹雨成花 2025-01-10 00:29:17

或者使用-std=gnu99,您可以禁用单个警告:

-Wno-declaration-after-statement

阅读info gcc

`-Wdeclaration-after-statement (C and Objective-C only)'
     Warn when a declaration is found after a statement in a block.
     This construct, known from C++, was introduced with ISO C99 and is
     by default allowed in GCC.  It is not supported by ISO C90 and was
     not supported by GCC versions before GCC 3.0.  *Note Mixed
     Declarations::.

Alternatively to use -std=gnu99 you can disable individual warnings:

-Wno-declaration-after-statement

Read info gcc:

`-Wdeclaration-after-statement (C and Objective-C only)'
     Warn when a declaration is found after a statement in a block.
     This construct, known from C++, was introduced with ISO C99 and is
     by default allowed in GCC.  It is not supported by ISO C90 and was
     not supported by GCC versions before GCC 3.0.  *Note Mixed
     Declarations::.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文