GCC 对C语言标准的的支持情况

概述

一门 编程语言,不但包括对应的语法,还包括对应的编译器(或解释器)、对应的标准库(或框架库)和相关工具

 

对于C语言,我们 使用如下三要素学习它。

语法:C语言标准

编译器(或解释器):gcc

库函数:标准要求的和gcc提供的。

 

GCC 对C语言标准的的支持情况

https://gcc.gnu.org/onlinedocs/gcc/Standards.html

 

2.1 C Language

The original ANSI C standard (X3.159-1989) was ratified in 1989 and published in 1990.

最初的ANSI C 标准(X3.159-1989)在1989年正式通过批准并在1990年发布。

 

This standard was ratified as an ISO standard (ISO/IEC 9899:1990) later in 1990.

这个标准在1990年下半年被批准成为一个国际标准(ISO/IEC 9899: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.

尽管ANSI 标准的章节被重新排序成为ISO标准,但是这些标准之间没有技术方面的差异。

 

The ANSI standard, but not the ISO standard, also came with a Rationale document.

ANSI 标准还包括一个 Rationale document。

 

This standard, in both its forms, is commonly known as C89, or occasionally as C90, from the dates of ratification.

ANSI 标准 俗称为 C89,有时也称 C90.

 

To select this standard in GCC, use one of the options -ansi-std=c90 or -std=iso9899:1990;

GCC 中,通过 下面选项 选择 ANSI C (c89 c90 iso9899:1990标准) -ansi-std=c90 或 -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.

如果想要 GCC 严格的按照选择的 C语言标准来进行工作,你应该使用 -pedantic 选项,这样不符合标准的语法会被报告为警告。(或者,如果你想要让不符合 标准的语法被报告为错误,你应该使用 -pedantic-errors 选项)

 

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.

Iso9899:1990 标准里面的错误,在随后的 1994和1996发布的两个技术勘误中被更正。GCC 不支持 未更正的标准(即,GCC 里面指定C90标准,指的是1996年技术勘误后的标准)

 

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.

1995年发布了对C90标准的一个修订标准。这份修订标准增加了 双字符组 和 __STDC_VERSION__  的宏定义。

 

关于 双字符组和三字符串 等,参考:

https://www.jb51.net/article/148250.htm

缘起

C语言的源程序的最低必须的字符集是基于7位ASCII码字符集,是 ISO 646-1983 Invariant Code Set 的一个超集。ISO 646最初是1972年颁布的一项国际化的7位ASCII标准,规定了12个字符所对应的 码位 保持对各国标准开放: # $ @ [ \ ] ^ ` { | } ~ 。 因此法国标准AFNOR NF Z 62010-1982把码位0x7c(ASCII码的 | )定义为ù,用法文键盘就难以输入C语言的位或运算符 | ;码位0x7e(ASCII码的 ~)定义为 ¨ (即 分音符 ),法文键盘就难以输入C语言的位非运算符 ~ 。 加拿大法语标准CSA Z243.4-1985中把码位0x5e(ASCII码的 ^ )在定义为É,导致难以输入C语言的异或运算符 ^ 。

1994年公布了一项C语言标准的修正案,引入了更具有可读性的5个双字符组。这也包括进了 C99 标准

 

 

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 -std=iso9899:199409 (with, as for other standard versions, -pedantic to receive all required diagnostics).

这个标准 俗称未 AMD1;这个修订标准有时 称为 C94 或 C95。GCC上,使用 选项 -std=iso9899:199409 来选择这个标准(和其他标准相同,使用 -pedantic 选项来让不符合标准的语法报告为警告。

 

A new edition of the ISO C standard was published in 1999 as ISO/IEC 9899:1999, and is commonly known as C99.

新版标准在 1999年发布,称为C99

 

(While in development, drafts of this standard version were referred to as C9X.)

(在这个标准的开发阶段,这份标准的部分内容也被gcc所支持,GCC对这标准称为C9X.)

 

GCC has substantially complete support for this standard version; see https://gcc.gnu.org/c99status.html for details.

GCC 基本上支持C99标准的所有内容。参见 https://gcc.gnu.org/c99status.html  获得支持情况的详细信息。

 

To select this standard, use -std=c99 or -std=iso9899:1999.

使用选项 -std=c99 或者-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.

C99 标准中的错误,在后面的2001、2004、2007年的三个技术勘误中被修改。GCC 不支持未修改的标准(即指定-std=c99 实际上使用的是 2007年勘误后的标准)

 

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.)

第四版本的C语言标准,C11在2011年发布。(在标准开发阶段,GCC使用C1X代指这些标准)

 

GCC has substantially complete support for this standard, enabled with -std=c11 or -std=iso9899:2011.

GCC 基本上支持所有的C11标准。使用选项  -std=c11 或 -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 -std=c17 or -std=iso9899:2017;

对C11的更正在2017年集成好,并在2018年发布,称为C17,通过选项 -std=c17 or -std=iso9899:2017 来选择这个标准。

 

the corrections are also applied with -std=c11, and the only difference between the options is the value of __STDC_VERSION__.

这些更正在使用选项 -std=c11 时,也会被应用。使用 -std=c11 和  -std=c17 的差别仅仅在 宏定义 __STDC_VERSION__ 不同。

 

A further version of the C standard, known as C2X, is under development; experimental and incomplete support for this is enabled with -std=c2x.

进一步的C标准,GCC代指为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.

通常,GCC 提供C语言的一些扩展,极少情况下,这些扩展和C语言标准有冲突。参见 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.

C99 标准中的一些特性在GCC的 C90扩展模式下会被应用。C11标准中的一些特性在gcc的C99扩展模式下会被应用。

 

Use of the -std options listed above disables these extensions where they conflict with the C standard version selected.

当GCC扩展和C语言标准冲突时,使用上面的 -std 选项选择对应的C语言标准来禁用扩展。

 

You may also select an extended version of the C language explicitly with -std=gnu90 (for C90 with GNU extensions), -std=gnu99 (for C99 with GNU extensions) or -std=gnu11 (for C11 with GNU extensions).

也可以 使用 下面选项,选择一个gcc扩展版本的 C语言标准。

-std=gnu90选择GCC扩展版本的C90标准。

std=gnu99选择GCC 扩展版本的 C99 标准。

 

The default, if no C language dialect options are given, is -std=gnu17.

如果没有选择C语言标准,默认选择是 -std=gnu17

 

The ISO C standard defines (in clause 4) two classes of conforming implementation.

C标准定义了两种实现:hosted implementationfreestanding implementation

 

conforming hosted implementation supports the whole standard including all the library facilities;

Hosted implementation 需要支持所有标准和(提供)所有的库。

 

conforming freestanding implementation is only required to provide certain library facilities:

freestanding implementation 只需要提供部分库功能。

 

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

freestanding implemantion需要提供 <float.h> <limits.h> <stdargs.h> 和 <stddef.h>

AMD1 标准后,再增加一个 <iso646.h>

C99 标准后,增加<stdbool.h> 和 <stdint.h>

C11 标准后,增加 <stdalign.h> 和 <stdnoreturn.h>

 

In addition, complex types, added in C99, are not required for freestanding implementations.

另外,C99 中增加的 complex 数据类型,在freestanding implementation 中不要求实现。

 

The standard also defines two environments for programs,

标准也定义了两种编程环境 freestanding environment 和hosted environment.

 

freestanding environment, required of all implementations

freestanding environment 编程环境,两种 implementation 都需要提供,

 

and which may not have library facilities beyond those required of freestanding implementations,

freestanding environment 编程环境中,可能没有上述 freestanding implementation 规定之外的其他库功能。

 

where the handling of program startup and termination are implementation-defined;

这种编程环境下,程序的启动和结束,都是各自(编译器)自己是决定如何实现。

 

and a hosted environment, which is not required,

hosted environment,是非必须提供给的(在freestanding implementation 下就不需要提供)

 

in which all the library facilities are provided and startup is through a function int main (void) or int main (int, char *[]).

在 hosted environment 下,所有标准定义的库功能都被提供,程序启动是通过 int main(void) 或 int main(int , char*[]) 。

 

 An OS kernel is an example of a program running in a freestanding environment;

OS 内核是 freestanding environment 环境下运行的C语言程序的一个示例。

 

 a program using the facilities of an operating system is an example of a program running in a hosted environment.

在操作系统上面运行的,使用操作系统提供的功能的程序是 hosted environment 环境下运行的C语言程序。

 

GCC aims towards being usable as a conforming freestanding implementation, or as the compiler for a conforming hosted implementation.

GCC 项目的目标是 成为一个可用的 freestanding  implementation;或者作为一个 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.

默认情况下,GCC 作为 hosted implementation 下面的编译器来工作。并且定义宏 __STDC_HOSTED__ 为 1,当ISO C函数被使用时,它们具有标准中定义的语义。

 

To make it act as a conforming freestanding implementation for a freestanding environment, use the option -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.

为了让GCC 作为 freestanding implementation 来工作,提供freestanding environment 编程环境,使用选项 -ffreestanding,GCC会将 宏 __STDC_HOSTED__ 定义为  0 ,并且(对标准中定义的函数名)不会假设它具有标准中定义的语义。以下备注的情况例外。

 

 

 To build an OS kernel, you may well still need to make your own arrangements for linking and startup. See Options Controlling C Dialect.

想要构建一个 OS 内核,你依然需要自己组织内核的连接和启动。见Options Controlling C Dialect.

 

GCC does not provide the library facilities required only of hosted implementations,

GCC 不提供只在 hosted implementation中要求的函数。

 

nor yet all the facilities required by C99 of freestanding implementations on all platforms.

也不是在所有平台上面都提供 C99标准下的 freestanding implementation 规定的函数。

 

To use the facilities of a hosted environment, you need to find them elsewhere (for example, in the GNU C library). See Standard Libraries.

想要使用 hosted implementation 下定义的函数,你需要从别的库中找到它们的实现。

 

Most of the compiler support routines used by GCC are present in libgcc, but there are a few exceptions.

大部分GCC 使用的编译器支持函数通过libgcc来提供。有若干例外。

 

GCC requires the freestanding environment provide memcpymemmovememset and memcmp.

GCC 要求 freestanding environment 环境提供 memcpy memmove memset 和 memcmp 函数。

 

Finally, if __builtin_trap is used, and the target does not implement the trap pattern, then GCC emits a call to abort.

最后,如果使用了 __builtin_trap函数,目标没有实现trap 模型,GCC 生成一个 abort()的调用。 【可以尽管调用 __builtin_trap() 函数,但是gcc会自己处理,或产生软件断点,或产生abort() 调用】

C/C++调试技巧-debugbreak

https://www.bilibili.com/read/cv1165694/

 

 

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

技术修订文档,Rationale documents 和C语言的发展历史相关的信息、见  https://gcc.gnu.org/readings.html

 

原文链接: https://www.cnblogs.com/zhangzhiwei122/p/15758274.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    GCC 对C语言标准的的支持情况

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/183041

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 上午10:19
下一篇 2023年2月12日 上午10:20

相关推荐