【问题标题】:compiling with c89 and c99 does gcc 4.4.2 default to c99?用 c89 和 c99 编译 gcc 4.4.2 是否默认为 c99?
【发布时间】:2011-01-08 12:21:36
【问题描述】:

我在 linux 上使用 gcc 4.4.2

我只是想知道 gcc 是否会自动默认以 c99 作为其最新标准进行编译?

如何指定是使用 c89 还是 c99 编译?

非常感谢您的建议,

【问题讨论】:

  • 默认仍然是 gnu89(即带有 GNU 扩展的 c89)。

标签: c c99 c89


【解决方案1】:

默认情况下不使用 C99 的一个原因是该标准尚未在编译器中完全实现。不过,我相信你可以在编译 gcc 时设置默认模式,所以如果标准的选择对你来说真的很重要,最好总是传递选项。

选项分别为-std=c99-std=c89

【讨论】:

  • 我通常用 c89 编译,因为它更便携。但是我喜欢 c99 的一些特性。但是,我不能使用 c99 标准,因为我需要使用仅支持 c89 的 VS 在 Windows 上编译。即使是最新版本的 VS 2010 也不会实现 c89。
  • 如果我检查GCC C99status,我找不到任何会影响大多数用例的缺失功能。您能否举一个可能会阻止使用 C99 编译的缺失功能的示例?
  • @RuudAlthuizen 该答案写于 2010 年。截至 2016 年,据我所知,仅缺少浮点的专家方面。 “ 中的浮点环境访问”被标记为“库功能,不需要编译器支持”,但实际上这绝对需要编译器支持,而 GCC 不提供。
  • @PascalCuoq 我确实注意到了时间戳。我添加了评论,因为问题特别提到了 GCC 4.4.2,这与支持状态无关。
【解决方案2】:

来自gcc(1) 手册页:

   -std=
       Determine the language standard.   This option is currently only
       supported when compiling C or C++.

....

       c99
       c9x
       iso9899:1999
       iso9899:199x
           ISO C99.  Note that this standard is not yet fully supported;
           see <http://gcc.gnu.org/gcc-4.4/c99status.html> for more
           information.  The names c9x and iso9899:199x are deprecated.

       gnu89
           GNU dialect of ISO C90 (including some C99 features). This is
           the default for C code.

       gnu99
       gnu9x
           GNU dialect of ISO C99.  When ISO C99 is fully implemented in
           GCC, this will become the default.  The name gnu9x is
           deprecated.

【讨论】:

    猜你喜欢
    • 2011-01-17
    • 2011-06-30
    • 1970-01-01
    • 2015-09-15
    • 2012-06-03
    • 2012-08-15
    • 2017-05-23
    • 2011-02-25
    相关资源
    最近更新 更多