C语言 当前 GCC(尤其是在 Ubuntu 上)的默认 C -std 标准版本是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14737104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the default C -std standard version for the current GCC (especially on Ubuntu)?
提问by ncmathsadist
When I ask to see the current version of cc I get this.
当我要求查看 cc 的当前版本时,我得到了这个。
$ cc --version
cc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
What I would like to know is which of c89, c90, c99 or c11 is being used.
我想知道的是正在使用 c89、c90、c99 或 c11 中的哪一个。
回答by Keith Thompson
This is explained in depth in the gcc manual, available (if it's installed) by typing info gccor online here. The relevant section of the 4.7.2 manual is here.
这在 gcc 手册中进行了深入解释,可info gcc通过在此处键入或在线获得(如果已安装)。4.7.2 手册的相关部分在这里。
By default, gcc does not conform to any of the ANSI/ISO C standards. The current default is equivalent to -std=gnu90, which is the 1989/1990 standard with GNU-specific extensions. (Some diagnostics required by the language standard are not issued.) Version 5.1.0, released 2015-04-22, changed the default from -std=gnu90to -std=gnu11, as documented here.
默认情况下,gcc 不符合任何 ANSI/ISO C 标准。当前的默认值等效于-std=gnu90,这是具有 GNU 特定扩展的 1989/1990 标准。(语言标准要求的某些诊断未发布。) 2015 年 4 月 22 日发布的 5.1.0 版将默认值从 更改-std=gnu90为-std=gnu11,如此处所述。
If you want standard conformance, you can use any of the following:
如果您想要符合标准,可以使用以下任何一种:
-std=c90 -pedantic
-std=c99 -pedantic
-std=c11 -pedantic
-std=c90can also be spelled -ansi, -std=c89, or -std=iso9899:1990.
-std=c90也可以拼写为-ansi, -std=c89, 或-std=iso9899:1990。
-std=iso9899:199409supports the C90 standard plus the 1995 amendment, which added a few minor features (all of which are also in C99).
-std=iso9899:199409支持 C90 标准加上 1995 修正案,其中增加了一些小功能(所有这些也在 C99 中)。
-std=c99can also be spelled -std=c9xor -std=iso9899:1999(the name c9xwas used before the standard was published). C99 support is not quite complete, but it's close.
-std=c99也可以拼写-std=c9x或-std=iso9899:1999(该名称c9x在标准发布之前使用)。C99 支持不是很完整,但已经很接近了。
-std=c11can also be spelled -std=c0xor -std=iso9899:2011(the name c0xwas used before the final standard was published; it was wrongly assumed that xwould not exceed 9). C11 support is also incomplete; the current status is summarized here.
-std=c11也可以拼写-std=c0x或-std=iso9899:2011(该名称c0x在最终标准发布之前使用;错误地认为x不会超过 9)。C11 支持也不全;此处总结了当前状态。
The -pedanticoption causes gcc to print required diagnostics for violations of constraints and syntax rules. In some cases, those diagnostics are merely warnings -- and there's no easy way to distinguish between those warnings and other warnings that aren't required by the language. Replace -pedanticby -pedantic-errorsto cause gcc to treat language violations as fatal errors.
该-pedantic选项会导致 gcc 打印所需的违反约束和语法规则的诊断信息。在某些情况下,这些诊断只是警告——并且没有简单的方法来区分这些警告和语言不需要的其他警告。更换-pedantic通过-pedantic-errors对导致GCC对待语言侵犯致命错误。
A quick history of the standard:
标准简史:
- C89 was the first official C standard, published by ANSIin 1989.
- C90 was the ISOversion of the standard, describing exactly the same language as C89. ANSI officially adopted ISO's version of the standard. There were two Technical Corrigenda, correcting some errors.
- C95 was an amendment to C90, adding a few features, mainly digraphs and wide character support. As far as I know, a merged version was never published.
- C99 was issued by ISO in 1999. There were three Technical Corrigenda.
- C11 was issued by ISO in 2011. There has been one Technical Corrigendum, fixing the definitions of
__STDC_VERSION__and__STDC_LIB_EXT1__.
- C89 是第一个官方 C 标准,由ANSI于 1989 年发布。
- C90 是该标准的 ISO版本,描述的语言与 C89 完全相同。ANSI 正式采用了 ISO 版本的标准。有两个技术勘误表,纠正了一些错误。
- C95 是对 C90 的修正,增加了一些特性,主要是有向图和宽字符支持。据我所知,合并版本从未发布过。
- C99 于 1999 年由 ISO 发布,共有三项技术勘误表。
- C11 于 2011 年由 ISO 发布。有一个技术勘误,修正了
__STDC_VERSION__和的定义__STDC_LIB_EXT1__。
ANSI did not issue its own versions of the 1999 or 2011 standards, adopting the ISO standards instead.
ANSI 没有发布自己的 1999 年或 2011 年标准版本,而是采用了 ISO 标准。
N1256is a freely available draft of the C99 standard, with the 3 Technical Corrigenda merged into it.
N1256是 C99 标准的免费草案,其中合并了 3 个技术勘误表。
N1570is a freely available draft of the C11 standard. There are some minor differences between it and the published C11 standard, plus one Technical Corrigendum. For more details, see my answerto this question.
N1570是 C11 标准的免费可用草案。它与已发布的 C11 标准以及一份技术勘误表之间存在一些细微差别。有关更多详细信息,请参阅我对这个问题的回答。
回答by Varun Garg
useful information from info gccfor gcc6 and https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/Standards.html#Standardsfor gcc5
来自info gccgcc6 和https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/Standards.html#Standardsfor gcc5 的有用信息
gcc version 6.3.1- 7.3.1
gcc 版本6.3.1-7.3.1
2.1 C Language
==============
The default, if no C language dialect options are given, is
'-std=gnu11'.
2.2 C++ Language
================
The default, if no C++ language dialect options are given, is
'-std=gnu++14'.
gcc version 5.4.0
海湾合作委员会版本 5.4.0
2.1 C Language
==============
The default, if no C language dialect options are given, is -std=gnu11
2.2 C++ Language
================
The default, if no C++ language dialect options are given, is -std=gnu++98
For C, default mode remains std=gnu11, but for C++ it has jumped from std=gnu++98 to std=gnu++14
对于 C,默认模式仍然是 std=gnu11,但对于 C++,它已经从 std=gnu++98 跳转到 std=gnu++14
回答by ablm
The first line will give your GCC version (4.7.2)
第一行将提供您的 GCC 版本 (4.7.2)
(Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
(Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
When you compile your code, you can specify which C/C++ revision you want to use, by adding -std=c99or -std=c99...
编译代码时,您可以指定要使用的 C/C++ 修订版,通过添加-std=c99或-std=c99...
Note gnu89is used by default.
gnu89默认情况下使用注释。
回答by Randy Howard
One thing to be aware of, the -std= option to gcc can not be used to "sandbox" the compiler into not supporting constructs from later versions of standard C. This is true with or without -pedantic
需要注意的一件事是,gcc 的 -std= 选项不能用于将编译器“沙箱化”为不支持来自标准 C 的更高版本的构造。无论是否存在,这都是正确的 -pedantic
You can not depend upon on gcc -std=c89 -pedanticto give you errors or warnings if you try to compile using some C99 code constructs. In some cases it will, in others it will not. For example, it will happily compile code that uses the %zuformat specifier in a printf() call, even though it wasn't added until C99.
gcc -std=c89 -pedantic如果您尝试使用某些 C99 代码构造进行编译,则不能依赖于向您提供错误或警告。在某些情况下会,在其他情况下不会。例如,它会很高兴地编译%zu在 printf() 调用中使用格式说明符的代码,即使它直到 C99 才被添加。
回答by user116480
Default gcc command is the GNU dialect of ISO C90 (including some C99 features). This is the default for C code.
默认的 gcc 命令是 ISO C90 的 GNU 方言(包括一些 C99 功能)。这是 C 代码的默认设置。

