C Language Standards Supported by GCC (GCC 支持的C語言標準)

Using the GNU Compiler Collection

Language Standards Supported by GCC

GCC支持的語言標準

For each language compiled by GCC for which there is a standard,

對於由GCC編譯的每種語言都有一個標準

GCC attempts to follow one or more versions of that standard,

GCC嘗試遵循該標準的一個或多個版本

possibly with some exceptions, and possibly with some extensions.

可能有一些例外,也可能有一些擴展。

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標準(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 標準相比於 ISO 標準,還附有一個基本原理的文檔。

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

這個標準自批准之日起以兩種形式存在,通常被稱爲C89,有時也稱爲C90

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

要在GCC中選擇此標準,可使用選項 '-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 Section 3.4 [Options Controlling C Dialect], page 33.

爲了獲得該標準所需要的所有診斷信息,
您還應該指定'-pedantic'( 或'-pedantic-errors',如果您希望它們是錯誤而不是警告 )。
詳見3.4節 [ 控制C語言選項 ], 33頁

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.

在 1994年 和 1996年, 1990年 ISO C 標準的錯誤已在兩份發佈的技術勘誤表中得到糾正.
GCC不支持未校正的版本。

An amendment to the 1990 standard was published in 1995.

1995年出版了1990年標準的修正案。

This amendment added digraphs and __STDC_VERSION__ to the language, but otherwise concerned the library.

這個修正案添加了 digraphs 和 __STDC_VERSION__ 到 C 語言中,但是並沒有涉及這個庫的其他方面

This amendment is commonly known as AMD1; the amended standard is sometimes known as C94 or C95.

這個修正案俗稱爲 AMD1; 修訂後的標準被稱爲 C94C95

To select this standard in GCC, use the option‘-std=iso9899:199409’(with, as for other standard versions,‘-pedantic’to receive all required diagnostics).

要在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.
(While in development, drafts of this standard version were referred to as C9X.)

1999年 ISO C standard 的新版本作爲 ISO/IEC 9899:1999 出版,通常被稱爲 C99
(在開發時,本標準版的草案被稱爲 C9X)

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

GCC 對此標準的版本基本完全支持; 詳見 http://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.

在2001、2004和2007年, 1999年ISO C標準的錯誤已在三份發佈的技術勘誤表中得到糾正
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.)

2011年 C標準的第四版,被稱爲 C11,作爲ISO/IEC 9899:2011出版。
在開發過程中,本標準版的草案被稱爲 C1X

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

GCC已經完全支持這個標準,啓動選項 '-std=c11''-std=iso9899:2011'

By default, GCC provides some extensions to the C language that, on rare occasions conflict with the C standard.
See Chapter 6 [Extensions to the C Language Family], page 403.

默認情況下,GCC爲C語言提供了一些擴展,在極少的情況下,與C標準相沖突。
詳見第6章 [ 擴展C語言家族 ], 403頁

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標準的部分特性被擴展到了 C90 模式,C11 標準的部分特性被擴展到了 C90 和 C99 模式

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

使用上面列出的 '-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).

您還可以使用
'-std=gnu90' ( 對應 C90 GNU擴展 ),
'-std=gnu99' ( 對應 C99 GNU擴展 ) 或
'-std=gnu11' ( 對應 C11 GNU擴展 ) 這些選項可以明確地指定 C 語言的擴展版本

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

默認情況下,如果沒有給出C語言方言選項,默認爲'std = gnu11'


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

ISO C 標準( 在第四節 ) 規定了兩個符合標準的實現方式

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

一個是符合標準的託管實現方式(hosted implementation) 能夠支持嚴格遵循標準的全部庫文件(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.

而另一個是符合標準的獨立實現方式(freestanding implementation) 僅支持某幾個庫文件 :
這些庫文件有 <float.h>, <limits.h>, <stdarg.h>, 和<stddef.h>;
到 AMD1 修正案時,還有 <iso646.h>
到 C99 時, 還有<stdbool.h><stdint.h>;
再到 C11 時, 還有<stdalign.h><stdnoreturn.h>.
此外,在C99 中添加的 complex 類型,在獨立實現方式(freestanding implementation)中是不需要的

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;

該標準還爲程序定義了兩個環境,一個是 獨立環境(freestanding environment)
要求所有的實現 除了那些獨立實現(freestanding implementation)所需的庫之外不依賴其他庫設施
而且要在指定的地方實現已定義的程序的啓動和停止

and a hosted environment, which is not required, 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;

系統內核就是一個在獨立環境(freestanding environment)中運行的程序示例;

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

而使用操作系統設施的程序就是一個在託管環境(hosted environment)中運行的程序示例。

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, defning __STDC_HOSTED__ as 1
and presuming that when the names of ISO C functions are used, they have the semantics defned 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’;

爲使 GCC 作爲獨立環境(freestanding environment)下的獨立實現(freestanding implementation), 可以使用'-ffreestanding' 選項

it then defnes __STDC_HOSTED__ to 0 and does not make assumptions
about the meanings of function names from the standard library, with exceptions noted below.

該選項可以使__STDC_HOSTED__定義爲 0 並且不對標準庫中函數名做出已定義的假設,下面提到了例外的情況

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

要構建操作系統內核,您可能還需要自行安排鏈接和啓動。
詳見3.4節 [ 控制C語言選項 ], 33頁

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.

GCC本身並不提供託管實現(hosted implementations) 所需的庫設施,
也不提供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 Section 13.5 [Standard Libraries], page 788.

要使用託管環境的設施,您需要在其他地方找到它們 (比如, GNU 的 C 庫)
詳見 13.5 節 [ 標準庫 ],788頁

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 memcpy, memmove, memset 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 pattern),那麼GCC將發出一箇中止調用。

For references to Technical Corrigenda, Rationale documents and information concerning the history of C that is available online,
see http://gcc.gnu.org/readings.html

參考文獻,在線可用的C歷史的闡述文檔和信息,
詳見 http://gcc.gnu.org/readings.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章