使用C89和C99编译,GCC 4.4.2默认采用C99吗?

6

我在Linux上使用gcc 4.4.2。

我想知道,gcc是否会自动将c99作为默认标准进行编译?

如果我想使用c89或c99进行编译,该怎么指定呢?

非常感谢您的建议。


2
默认仍为gnu89(即带有GNU扩展的c89)。 - R Samuel Klatchko
2个回答

11

不默认使用C99的一个原因是编译器尚未完全实现此标准。然而,我认为您可以在编译gcc时设置默认模式,因此如果标准的选择真的很重要,最好始终传递选项。

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


我通常使用 c89 进行编译,因为它更具可移植性。但是,我喜欢 c99 的一些功能。然而,我不能使用 c99 标准,因为我需要在使用 VS 的 Windows 上进行编译,而 VS 仅支持 c89。即使是最新版本的 VS 2010 也不会实现 c89。 - ant2009
如果我查看GCC C99状态,我找不到任何缺失的功能,这些功能会影响大多数用例。您能举一个可能会阻止使用C99编译的缺失功能的例子吗? - Ruud Althuizen
@RuudAlthuizen 那个答案是在2010年写的。截至2016年,据我所知,只有浮点数的专家方面缺失。“<fenv.h>中的浮点环境访问”被标记为“库特性,不需要编译器支持”,但实际上这绝对需要编译器支持,而GCC并没有提供。 - Pascal Cuoq
@PascalCuoq 我注意到了时间戳。我添加评论是因为问题特别提到了GCC 4.4.2,但这并不影响支持状态。 - Ruud Althuizen

9

来自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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接