The original ANSI C standard(X3.159-1989) was ratified in 1989 and published in 1990. This standard was ratified as an ISO standard(ISO/IEC 9899:1990) later in 1990. There were no technical differences between these publications, although the sections of the ANSI standard were renumbered and became clauses in the ISO standard. The ANSI standard, but not the ISO standard, also came with a Rationale document. This standard, in both its forms, is commonly known as C89, or occasionally as C90, from the dates of ratification. To select this standard in GCC, use one of the options最初的 ANSI C 标准 (X3.159-1989) 于 1989 年获得批准并于 1990 年发布。该标准于 1990 年晚些时候被批准为 ISO 标准 (ISO/IEC 9899:1990)。这些出版物之间没有技术差异,尽管 ANSI 标准的章节被重新编号并成为 ISO 标准中的条款。 ANSI 标准,但不是 ISO 标准,也附带了一个基本原理文档。从批准之日起,该标准的两种形式通常称为 C89,有时也称为 C90。要在 GCC 中选择此标准,请使用其中一个选项
-ansi,-std=c90 -std=c90 or -std=iso9899:1990-std=iso9899:1990; to obtain all the diagnostics required by the standard, you should also specify
;要获得标准要求的所有诊断,您还应该指定
-pedantic -迂腐 (or -pedantic-errors -迂腐错误 if you want them to be errors rather than warnings). See Options Controlling C Dialect.
如果您希望它们是错误而不是警告)。请参阅控制 C 方言的选项。Errors in the 1990 ISO C standard were corrected in two Technical Corrigenda published in 1994 and 1996. GCC does not support the uncorrected version.1990 年 ISO C 标准中的错误在 1994 年和 1996 年发布的两个技术勘误表中得到纠正。GCC 不支持未纠正的版本。An amendment to the 1990 standard was published in 1995. This amendment added digraphs and __STDC_VERSION__ to the language, but otherwise concerned the library. This amendment is commonly known as AMD1; the amended standard is sometimes known as C94 or C95. To select this standard in GCC, use the option
1990 年标准的修正案于 1995 年发布。该修正案在语言中添加了二合字母和 __STDC_VERSION__ ,但在其他方面与图书馆有关。此修正案通常称为 AMD1;修订后的标准有时称为 C94 或 C95。要在 GCC 中选择此标准,请使用选项
-std=iso9899:199409-std=iso9899:199409(with, as for other standard versions,
(对于其他标准版本,
-pedantic -迂腐 to receive all required diagnostics).
接收所有必需的诊断)。A new edition of the ISO C standard was published in 1999 as ISO/IEC 9899:1999, and is commonly known as C99.(While in development, drafts of this standard version were referred to as C9X.) GCC has substantially complete support for this standard version; see https://gcc.gnu.org/c99status.html for details. To select this standard, use
ISO C 标准的新版本于 1999 年作为 ISO/IEC 9899:1999 发布,通常称为 C99。 (在开发过程中,这个标准版本的草案被称为 C9X。)GCC 基本上完全支持这个标准版本;有关详细信息,请参阅 https://gcc.gnu.org/c99status.html 。要选择此标准,请使用-std=c99 -std=c99 or -std=iso9899:1999-std=iso9899:1999.Errors in the 1999 ISO C standard were corrected in three Technical Corrigenda published in 2001,2004 and 2007. GCC does not support the uncorrected version.1999 ISO C 标准中的错误已在 2001、2004 和 2007 年发布的三个技术勘误中得到更正。GCC 不支持未更正的版本。A fourth version of the C standard, known as C11, was published in 2011 as ISO/IEC 9899:2011.(While in development, drafts of this standard version were referred to as C1X.) GCC has substantially complete support for this standard, enabled with
C 标准的第四个版本,称为 C11,于 2011 年作为 ISO/IEC 9899:2011 发布。 (在开发过程中,这个标准版本的草案被称为 C1X。)GCC 基本上完全支持这个标准,启用
-std=c11 -std=c11 or -std=iso9899:2011-std=iso9899:2011. A version with corrections integrated was prepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it is known as C17 and is supported with
.2017 年准备了一个包含更正的版本,并于 2018 年作为 ISO/IEC 9899:2018 发布;它被称为 C17 并支持
-std=c17 -std=c17 or -std=iso9899:2017-std=iso9899:2017; the corrections are also applied with
;更正也适用于
-std=c11 -std=c11, and the only difference between the options is the value of __STDC_VERSION__.
,选项之间的唯一区别是 __STDC_VERSION__ 的值。A further version of the C standard, known as C2X, is under development; experimental and incomplete support for this is enabled with
C 标准的另一个版本,称为 C2X,正在开发中;对此启用了实验性和不完整的支持
-std=c2x -std=c2x.By default, GCC provides some extensions to the C language that, on rare occasions conflict with the C standard. See Extensions to the C Language Family. Some features that are part of the C99 standard are accepted as extensions in C90 mode, and some features that are part of the C11 standard are accepted as extensions in C90 and C99 modes. Use of the
默认情况下,GCC 为 C 语言提供了一些扩展,在极少数情况下会与 C 标准发生冲突。请参阅 C 语言系列的扩展。属于 C99 标准的一些功能在 C90 模式中被接受为扩展,而属于 C11 标准的一些功能在 C90 和 C99 模式中被接受为扩展。使用的
-std options listed above disables these extensions where they conflict with the C standard version selected. You may also select an extended version of the C language explicitly with
上面列出的选项会禁用这些与所选 C 标准版本冲突的扩展。您也可以明确选择 C 语言的扩展版本
-std=gnu90 -std=gnu90(for C90 with GNU extensions),
(对于带有 GNU 扩展的 C90),
-std=gnu99 -std=gnu99(for C99 with GNU extensions) or
(对于带有 GNU 扩展的 C99)或
-std=gnu11 -std=gnu11(for C11 with GNU extensions).
(对于带有 GNU 扩展的 C11)。The default,if no C language dialect options are given, is
如果没有给出 C 语言方言选项,则默认为
-std=gnu17 -std=gnu17.The ISO C standard defines(in clause 4) two classes of conforming implementation. A conforming hosted implementation supports the whole standard including all the library facilities; a conforming freestanding implementation is only required to provide certain library facilities: those in <float.h>,<limits.h>,<stdarg.h>, and <stddef.h>; since AMD1, also those in <iso646.h>; since C99, also those in <stdbool.h> and <stdint.h>; and since C11, also those in <stdalign.h> and <stdnoreturn.h>. In addition, complex types, added in C99, are not required for freestanding implementations.
ISO C 标准定义(在条款 4 中)两类符合性实现。符合标准的托管实现支持包括所有库设施在内的整个标准;符合要求的独立实现只需要提供某些库设施: <float.h> 、 <limits.h> 、 <stdarg.h> 和 <stddef.h> 中的设施;自 AMD1 以来,还有 <iso646.h> 中的那些;自 C99 以来,还有 <stdbool.h> 和 <stdint.h> 中的那些;从 C11 开始,还有 <stdalign.h> 和 <stdnoreturn.h> 中的那些。此外,独立实现不需要 C99 中添加的复杂类型。The standard also defines two environments for programs, a freestanding environment, required of all implementations and which may not have library facilities beyond those required of freestanding implementations, where the handling of program startup and termination are implementation-defined; and a hosted environment, which is not required, in which all the library facilities are provided and startup is through a function intmain(void) or intmain(int,char*[]). An OS kernel is an example of a program running in a freestanding environment; a program using the facilities of an operating system is an example of a program running in a hosted environment.
该标准还为程序定义了两个环境,一个独立环境,所有实现都需要它,并且可能没有超出独立实现所需的库设施,其中程序启动和终止的处理是实现定义的;和一个托管环境,这不是必需的,其中提供了所有库设施,并且启动是通过函数 intmain(void) 或 intmain(int,char*[]) 进行的。操作系统内核是在独立环境中运行的程序的一个例子;使用操作系统功能的程序是在托管环境中运行的程序的一个例子。GCC aims towards being usable as a conforming freestanding implementation, or as the compiler for a conforming hosted implementation. By default, it acts as the compiler for a hosted implementation, defining __STDC_HOSTED__ as 1 and presuming that when the names of ISO C functions are used, they have the semantics defined in the standard. To make it act as a conforming freestanding implementation for a freestanding environment, use the option
GCC 的目标是可用作符合标准的独立实现,或用作符合标准的托管实现的编译器。默认情况下,它充当托管实现的编译器,将 __STDC_HOSTED__ 定义为 1 并假定在使用 ISO C 函数的名称时,它们具有标准中定义的语义。要使其充当独立环境的一致独立实现,请使用该选项
-ffreestanding -独立式; it then defines __STDC_HOSTED__ to 0 and does not make assumptions about the meanings of function names from the standard library, with exceptions noted below. To build an OS kernel, you may well still need to make your own arrangements for linking and startup. See Options Controlling C Dialect.;然后它将 __STDC_HOSTED__ 定义为 0 ,并且不对标准库中的函数名称的含义做出假设,例外情况如下所述。要构建操作系统内核,您可能仍然需要自己安排链接和启动。请参阅控制 C 方言的选项。GCC does not provide the library facilities required only of hosted implementations, nor yet all the facilities required by C99 of freestanding implementations on all platforms. To use the facilities of a hosted environment, you need to find them elsewhere(for example, in the GNU C library). See Standard Libraries.
GCC 不提供仅托管实现所需的库设施,也不提供 C99 在所有平台上独立实现所需的所有设施。要使用托管环境的设施,您需要在其他地方找到它们(例如,在 GNU C 库中)。请参阅标准库。Most of the compiler support routines used by GCC are present in
GCC 使用的大多数编译器支持例程都存在于
libgcc, but there are a few exceptions. GCC requires the freestanding environment provide memcpy, memmove, memset and memcmp. Finally,if __builtin_trap is used, and the target does not implement the trap pattern, then GCC emits a call to abort., 但也有少数例外。 GCC 要求独立环境提供 memcpy 、 memmove 、 memset 和 memcmp 。最后,如果使用 __builtin_trap ,并且目标没有实现 trap 模式,那么 GCC 发出对 abort 的调用。For references to Technical Corrigenda, Rationale documents and information concerning the history of C that is available online, see https://gcc.gnu.org/readings.html
有关在线提供的技术勘误、基本原理文档和有关 C 历史的信息的参考,请参阅 https://gcc.gnu.org/readings.html
GNUC提供了ISO标准C中没有的几种语言特性
要测试这些特性在条件编译中的可用性,请检查预定义的宏__GNUC__,该宏始终在GCC下定义。
这些扩展在C和Objective-C中可用。它们中的大多数在C++中也可用。
有关仅适用于C++的扩展,请参阅第7章[C++语言的扩展],第901页。
Some features that are in ISO C99 but not C90 or C++ are also, as extensions, accepted by GCC in C90 mode and in C++.
在ISO C99(而不是 C90 /C++) 中的一些特性 也被 C90模式/C++ 作为扩展
9 Binary Compatibility
二进制兼容性包含几个相关概念:
ABI
ABI conformance
calling conventions
...