语言标准版本与编译器版本
language standard version versus compiler version
C
版本(例如C99
)和C
编译器版本(例如4.9.3
)有什么区别
$ ./arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977 with DYNAMIC_REENT by Ambarella]
Copyright (C) 2014 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.
如何判断我是否至少使用了 C99 以便我可以利用某些宏。
C 版本是 C 标准的名称。
历史顺序的主要标准:
- K&R
- ANSI(对于 ANSI 又称为 C89,对于 ISO 又称为 C90)
- C99
- C11
随着 C 语言在过去 40 年中的发展,这些标准中引入了新的或修改后的功能。
gcc compiler version - 就是软件的版本。旧版本可能不支持更新的 C 标准。您可以使用命令行选项告知编译器您的代码符合什么标准:
2.1 C Language
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
, -std=c90
or
-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.
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.
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 -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
http://gcc.gnu.org/c99status.html for details. To select this
standard, use -std=c99
or -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.
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 -std=c11
or
-std=iso9899:2011
. A version with corrections integrated is known as C17 and is supported with -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__
.
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 -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 -std=gnu90
(for C90
with GNU extensions), -std=gnu99
(for C99 with GNU extensions) or
-std=gnu11
(for C11 with GNU extensions).
The default, if no C language dialect options are given, is
-std=gnu11
.
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.
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 int main (void)
or int main (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.
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
-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.
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.
Most of the compiler support routines used by GCC are present in
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.
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
版本(例如C99
)和C
编译器版本(例如4.9.3
)有什么区别
$ ./arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977 with DYNAMIC_REENT by Ambarella]
Copyright (C) 2014 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.
如何判断我是否至少使用了 C99 以便我可以利用某些宏。
C 版本是 C 标准的名称。
历史顺序的主要标准:
- K&R
- ANSI(对于 ANSI 又称为 C89,对于 ISO 又称为 C90)
- C99
- C11
随着 C 语言在过去 40 年中的发展,这些标准中引入了新的或修改后的功能。
gcc compiler version - 就是软件的版本。旧版本可能不支持更新的 C 标准。您可以使用命令行选项告知编译器您的代码符合什么标准:
2.1 C Language
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
,-std=c90
or-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.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.
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-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 http://gcc.gnu.org/c99status.html for details. To select this standard, use
-std=c99
or-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.
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
-std=c11
or-std=iso9899:2011
. A version with corrections integrated is known as C17 and is supported with-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__
.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
-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-std=gnu90
(for C90 with GNU extensions),-std=gnu99
(for C99 with GNU extensions) or-std=gnu11
(for C11 with GNU extensions).The default, if no C language dialect options are given, is
-std=gnu11
.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.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
int main (void)
orint main (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.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-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.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.
Most of the compiler support routines used by GCC are present in 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.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