1*ec02198aSmrg@c Copyright (C) 2000-2020 Free Software Foundation, Inc.
210d565efSmrg@c This is part of the GCC manual.
310d565efSmrg@c For copying conditions, see the file gcc.texi.
410d565efSmrg
510d565efSmrg@node Standards
610d565efSmrg@chapter Language Standards Supported by GCC
710d565efSmrg
810d565efSmrgFor each language compiled by GCC for which there is a standard, GCC
910d565efSmrgattempts to follow one or more versions of that standard, possibly
1010d565efSmrgwith some exceptions, and possibly with some extensions.
1110d565efSmrg
1210d565efSmrg@section C Language
1310d565efSmrg@cindex C standard
1410d565efSmrg@cindex C standards
1510d565efSmrg@cindex ANSI C standard
1610d565efSmrg@cindex ANSI C
1710d565efSmrg@cindex ANSI C89
1810d565efSmrg@cindex C89
1910d565efSmrg@cindex ANSI X3.159-1989
2010d565efSmrg@cindex X3.159-1989
2110d565efSmrg@cindex ISO C standard
2210d565efSmrg@cindex ISO C
2310d565efSmrg@cindex ISO C90
2410d565efSmrg@cindex ISO/IEC 9899
2510d565efSmrg@cindex ISO 9899
2610d565efSmrg@cindex C90
2710d565efSmrg@cindex ISO C94
2810d565efSmrg@cindex C94
2910d565efSmrg@cindex ISO C95
3010d565efSmrg@cindex C95
3110d565efSmrg@cindex ISO C99
3210d565efSmrg@cindex C99
3310d565efSmrg@cindex ISO C9X
3410d565efSmrg@cindex C9X
3510d565efSmrg@cindex ISO C11
3610d565efSmrg@cindex C11
3710d565efSmrg@cindex ISO C1X
3810d565efSmrg@cindex C1X
39c7a68eb7Smrg@cindex ISO C17
40c7a68eb7Smrg@cindex C17
410fc04c29Smrg@cindex ISO C2X
420fc04c29Smrg@cindex C2X
4310d565efSmrg@cindex Technical Corrigenda
4410d565efSmrg@cindex TC1
4510d565efSmrg@cindex Technical Corrigendum 1
4610d565efSmrg@cindex TC2
4710d565efSmrg@cindex Technical Corrigendum 2
4810d565efSmrg@cindex TC3
4910d565efSmrg@cindex Technical Corrigendum 3
5010d565efSmrg@cindex AMD1
5110d565efSmrg@cindex freestanding implementation
5210d565efSmrg@cindex freestanding environment
5310d565efSmrg@cindex hosted implementation
5410d565efSmrg@cindex hosted environment
5510d565efSmrg@findex __STDC_HOSTED__
5610d565efSmrg
5710d565efSmrg@opindex std
5810d565efSmrg@opindex ansi
5910d565efSmrg@opindex pedantic
6010d565efSmrg@opindex pedantic-errors
6110d565efSmrgThe original ANSI C standard (X3.159-1989) was ratified in 1989 and
6210d565efSmrgpublished in 1990.  This standard was ratified as an ISO standard
6310d565efSmrg(ISO/IEC 9899:1990) later in 1990.  There were no technical
6410d565efSmrgdifferences between these publications, although the sections of the
6510d565efSmrgANSI standard were renumbered and became clauses in the ISO standard.
6610d565efSmrgThe ANSI
6710d565efSmrgstandard, but not the ISO standard, also came with a Rationale
6810d565efSmrgdocument.
6910d565efSmrgThis standard, in both its forms, is commonly known as @dfn{C89}, or
7010d565efSmrgoccasionally as @dfn{C90}, from the dates of ratification.
7110d565efSmrgTo select this standard in GCC, use one of the options
7210d565efSmrg@option{-ansi}, @option{-std=c90} or @option{-std=iso9899:1990}; to obtain
7310d565efSmrgall the diagnostics required by the standard, you should also specify
7410d565efSmrg@option{-pedantic} (or @option{-pedantic-errors} if you want them to be
7510d565efSmrgerrors rather than warnings).  @xref{C Dialect Options,,Options
7610d565efSmrgControlling C Dialect}.
7710d565efSmrg
7810d565efSmrgErrors in the 1990 ISO C standard were corrected in two Technical
7910d565efSmrgCorrigenda published in 1994 and 1996.  GCC does not support the
8010d565efSmrguncorrected version.
8110d565efSmrg
8210d565efSmrgAn amendment to the 1990 standard was published in 1995.  This
8310d565efSmrgamendment added digraphs and @code{__STDC_VERSION__} to the language,
8410d565efSmrgbut otherwise concerned the library.  This amendment is commonly known
8510d565efSmrgas @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
8610d565efSmrg@dfn{C95}.  To select this standard in GCC, use the option
8710d565efSmrg@option{-std=iso9899:199409} (with, as for other standard versions,
8810d565efSmrg@option{-pedantic} to receive all required diagnostics).
8910d565efSmrg
9010d565efSmrgA new edition of the ISO C standard was published in 1999 as ISO/IEC
9110d565efSmrg9899:1999, and is commonly known as @dfn{C99}.  (While in
9210d565efSmrgdevelopment, drafts of this standard version were referred to as
9310d565efSmrg@dfn{C9X}.)  GCC has substantially
9410d565efSmrgcomplete support for this standard version; see
9510d565efSmrg@uref{http://gcc.gnu.org/c99status.html} for details.  To select this
9610d565efSmrgstandard, use @option{-std=c99} or @option{-std=iso9899:1999}.
9710d565efSmrg
9810d565efSmrgErrors in the 1999 ISO C standard were corrected in three Technical
9910d565efSmrgCorrigenda published in 2001, 2004 and 2007.  GCC does not support the
10010d565efSmrguncorrected version.
10110d565efSmrg
10210d565efSmrgA fourth version of the C standard, known as @dfn{C11}, was published
10310d565efSmrgin 2011 as ISO/IEC 9899:2011.  (While in development, drafts of this
10410d565efSmrgstandard version were referred to as @dfn{C1X}.)
10510d565efSmrgGCC has substantially complete support
10610d565efSmrgfor this standard, enabled with @option{-std=c11} or
1070fc04c29Smrg@option{-std=iso9899:2011}.  A version with corrections integrated was
1080fc04c29Smrgprepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it is
109c7a68eb7Smrgknown as @dfn{C17} and is supported with @option{-std=c17} or
110c7a68eb7Smrg@option{-std=iso9899:2017}; the corrections are also applied with
111c7a68eb7Smrg@option{-std=c11}, and the only difference between the options is the
112c7a68eb7Smrgvalue of @code{__STDC_VERSION__}.
11310d565efSmrg
1140fc04c29SmrgA further version of the C standard, known as @dfn{C2X}, is under
1150fc04c29Smrgdevelopment; experimental and incomplete support for this is enabled
1160fc04c29Smrgwith @option{-std=c2x}.
1170fc04c29Smrg
11810d565efSmrgBy default, GCC provides some extensions to the C language that, on
11910d565efSmrgrare occasions conflict with the C standard.  @xref{C
12010d565efSmrgExtensions,,Extensions to the C Language Family}.
12110d565efSmrgSome features that are part of the C99 standard
12210d565efSmrgare accepted as extensions in C90 mode, and some features that are part
12310d565efSmrgof the C11 standard are accepted as extensions in C90 and C99 modes.
12410d565efSmrgUse of the
12510d565efSmrg@option{-std} options listed above disables these extensions where
12610d565efSmrgthey conflict with the C standard version selected.  You may also
12710d565efSmrgselect an extended version of the C language explicitly with
12810d565efSmrg@option{-std=gnu90} (for C90 with GNU extensions), @option{-std=gnu99}
12910d565efSmrg(for C99 with GNU extensions) or @option{-std=gnu11} (for C11 with GNU
13010d565efSmrgextensions).
13110d565efSmrg
13210d565efSmrgThe default, if no C language dialect options are given,
13310d565efSmrgis @option{-std=gnu11}.
13410d565efSmrg
13510d565efSmrgThe ISO C standard defines (in clause 4) two classes of conforming
13610d565efSmrgimplementation.  A @dfn{conforming hosted implementation} supports the
13710d565efSmrgwhole standard including all the library facilities; a @dfn{conforming
13810d565efSmrgfreestanding implementation} is only required to provide certain
13910d565efSmrglibrary facilities: those in @code{<float.h>}, @code{<limits.h>},
14010d565efSmrg@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
14110d565efSmrg@code{<iso646.h>}; since C99, also those in @code{<stdbool.h>} and
14210d565efSmrg@code{<stdint.h>}; and since C11, also those in @code{<stdalign.h>}
14310d565efSmrgand @code{<stdnoreturn.h>}.  In addition, complex types, added in C99, are not
14410d565efSmrgrequired for freestanding implementations.
14510d565efSmrg
14610d565efSmrgThe standard also defines two environments for programs, a
14710d565efSmrg@dfn{freestanding environment}, required of all implementations and
14810d565efSmrgwhich may not have library facilities beyond those required of
14910d565efSmrgfreestanding implementations, where the handling of program startup
15010d565efSmrgand termination are implementation-defined; and a @dfn{hosted
15110d565efSmrgenvironment}, which is not required, in which all the library
15210d565efSmrgfacilities are provided and startup is through a function @code{int
15310d565efSmrgmain (void)} or @code{int main (int, char *[])}.  An OS kernel is an example
15410d565efSmrgof a program running in a freestanding environment;
15510d565efSmrga program using the facilities of an
15610d565efSmrgoperating system is an example of a program running in a hosted environment.
15710d565efSmrg
15810d565efSmrg@opindex ffreestanding
15910d565efSmrgGCC aims towards being usable as a conforming freestanding
16010d565efSmrgimplementation, or as the compiler for a conforming hosted
16110d565efSmrgimplementation.  By default, it acts as the compiler for a hosted
16210d565efSmrgimplementation, defining @code{__STDC_HOSTED__} as @code{1} and
16310d565efSmrgpresuming that when the names of ISO C functions are used, they have
16410d565efSmrgthe semantics defined in the standard.  To make it act as a conforming
16510d565efSmrgfreestanding implementation for a freestanding environment, use the
16610d565efSmrgoption @option{-ffreestanding}; it then defines
16710d565efSmrg@code{__STDC_HOSTED__} to @code{0} and does not make assumptions about the
16810d565efSmrgmeanings of function names from the standard library, with exceptions
16910d565efSmrgnoted below.  To build an OS kernel, you may well still need to make
17010d565efSmrgyour own arrangements for linking and startup.
17110d565efSmrg@xref{C Dialect Options,,Options Controlling C Dialect}.
17210d565efSmrg
17310d565efSmrgGCC does not provide the library facilities required only of hosted
17410d565efSmrgimplementations, nor yet all the facilities required by C99 of
17510d565efSmrgfreestanding implementations on all platforms.
17610d565efSmrgTo use the facilities of a hosted
17710d565efSmrgenvironment, you need to find them elsewhere (for example, in the
17810d565efSmrgGNU C library).  @xref{Standard Libraries,,Standard Libraries}.
17910d565efSmrg
18010d565efSmrgMost of the compiler support routines used by GCC are present in
18110d565efSmrg@file{libgcc}, but there are a few exceptions.  GCC requires the
18210d565efSmrgfreestanding environment provide @code{memcpy}, @code{memmove},
18310d565efSmrg@code{memset} and @code{memcmp}.
18410d565efSmrgFinally, if @code{__builtin_trap} is used, and the target does
18510d565efSmrgnot implement the @code{trap} pattern, then GCC emits a call
18610d565efSmrgto @code{abort}.
18710d565efSmrg
18810d565efSmrgFor references to Technical Corrigenda, Rationale documents and
18910d565efSmrginformation concerning the history of C that is available online, see
19010d565efSmrg@uref{http://gcc.gnu.org/readings.html}
19110d565efSmrg
19210d565efSmrg@section C++ Language
19310d565efSmrg
19410d565efSmrgGCC supports the original ISO C++ standard published in 1998,
19510d565efSmrgand the 2011 and 2014 revisions.
19610d565efSmrg
19710d565efSmrgThe original ISO C++ standard was published as the ISO standard (ISO/IEC
19810d565efSmrg14882:1998) and amended by a Technical Corrigenda published in 2003
19910d565efSmrg(ISO/IEC 14882:2003). These standards are referred to as C++98 and
20010d565efSmrgC++03, respectively. GCC implements the majority of C++98 (@code{export}
20110d565efSmrgis a notable exception) and most of the changes in C++03.  To select
20210d565efSmrgthis standard in GCC, use one of the options @option{-ansi},
20310d565efSmrg@option{-std=c++98}, or @option{-std=c++03}; to obtain all the diagnostics
20410d565efSmrgrequired by the standard, you should also specify @option{-pedantic} (or
20510d565efSmrg@option{-pedantic-errors} if you want them to be errors rather than
20610d565efSmrgwarnings).
20710d565efSmrg
20810d565efSmrgA revised ISO C++ standard was published in 2011 as ISO/IEC
20910d565efSmrg14882:2011, and is referred to as C++11; before its publication it was
21010d565efSmrgcommonly referred to as C++0x.  C++11 contains several changes to the
21110d565efSmrgC++ language, all of which have been implemented in GCC@. For details
212c7a68eb7Smrgsee @uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx11}.
21310d565efSmrgTo select this standard in GCC, use the option @option{-std=c++11}.
21410d565efSmrg
21510d565efSmrgAnother revised ISO C++ standard was published in 2014 as ISO/IEC
21610d565efSmrg14882:2014, and is referred to as C++14; before its publication it was
21710d565efSmrgsometimes referred to as C++1y.  C++14 contains several further
21810d565efSmrgchanges to the C++ language, all of which have been implemented in GCC@.
219c7a68eb7SmrgFor details see @uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx14}.
22010d565efSmrgTo select this standard in GCC, use the option @option{-std=c++14}.
22110d565efSmrg
222c7a68eb7SmrgThe C++ language was further revised in 2017 and ISO/IEC 14882:2017 was
223c7a68eb7Smrgpublished.  This is referred to as C++17, and before publication was
224c7a68eb7Smrgoften referred to as C++1z.  GCC supports all the changes in the new
225c7a68eb7Smrgspecification.  For further details see
226c7a68eb7Smrg@uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx1z}.  Use the option
227c7a68eb7Smrg@option{-std=c++17} to select this variant of C++.
22810d565efSmrg
22910d565efSmrgMore information about the C++ standards is available on the ISO C++
23010d565efSmrgcommittee's web site at @uref{http://www.open-std.org/@/jtc1/@/sc22/@/wg21/}.
23110d565efSmrg
23210d565efSmrgTo obtain all the diagnostics required by any of the standard versions
23310d565efSmrgdescribed above you should specify @option{-pedantic}
23410d565efSmrgor @option{-pedantic-errors}, otherwise GCC will allow some non-ISO C++
23510d565efSmrgfeatures as extensions. @xref{Warning Options}.
23610d565efSmrg
23710d565efSmrgBy default, GCC also provides some additional extensions to the C++ language
23810d565efSmrgthat on rare occasions conflict with the C++ standard.  @xref{C++
23910d565efSmrgDialect Options,Options Controlling C++ Dialect}.  Use of the
24010d565efSmrg@option{-std} options listed above disables these extensions where they
24110d565efSmrgthey conflict with the C++ standard version selected.  You may also
24210d565efSmrgselect an extended version of the C++ language explicitly with
24310d565efSmrg@option{-std=gnu++98} (for C++98 with GNU extensions), or
24410d565efSmrg@option{-std=gnu++11} (for C++11 with GNU extensions), or
24510d565efSmrg@option{-std=gnu++14} (for C++14 with GNU extensions), or
246c7a68eb7Smrg@option{-std=gnu++17} (for C++17 with GNU extensions).
24710d565efSmrg
24810d565efSmrgThe default, if
24910d565efSmrgno C++ language dialect options are given, is @option{-std=gnu++14}.
25010d565efSmrg
25110d565efSmrg@section Objective-C and Objective-C++ Languages
25210d565efSmrg@cindex Objective-C
25310d565efSmrg@cindex Objective-C++
25410d565efSmrg
25510d565efSmrgGCC supports ``traditional'' Objective-C (also known as ``Objective-C
25610d565efSmrg1.0'') and contains support for the Objective-C exception and
25710d565efSmrgsynchronization syntax.  It has also support for a number of
25810d565efSmrg``Objective-C 2.0'' language extensions, including properties, fast
25910d565efSmrgenumeration (only for Objective-C), method attributes and the
26010d565efSmrg@@optional and @@required keywords in protocols.  GCC supports
26110d565efSmrgObjective-C++ and features available in Objective-C are also available
26210d565efSmrgin Objective-C++@.
26310d565efSmrg
26410d565efSmrgGCC by default uses the GNU Objective-C runtime library, which is part
26510d565efSmrgof GCC and is not the same as the Apple/NeXT Objective-C runtime
26610d565efSmrglibrary used on Apple systems.  There are a number of differences
26710d565efSmrgdocumented in this manual.  The options @option{-fgnu-runtime} and
26810d565efSmrg@option{-fnext-runtime} allow you to switch between producing output
26910d565efSmrgthat works with the GNU Objective-C runtime library and output that
27010d565efSmrgworks with the Apple/NeXT Objective-C runtime library.
27110d565efSmrg
27210d565efSmrgThere is no formal written standard for Objective-C or Objective-C++@.
27310d565efSmrgThe authoritative manual on traditional Objective-C (1.0) is
27410d565efSmrg``Object-Oriented Programming and the Objective-C Language'':
27510d565efSmrg@uref{http://www.gnustep.org/@/resources/@/documentation/@/ObjectivCBook.pdf}
27610d565efSmrgis the original NeXTstep document.
27710d565efSmrg
27810d565efSmrgThe Objective-C exception and synchronization syntax (that is, the
27910d565efSmrgkeywords @code{@@try}, @code{@@throw}, @code{@@catch},
28010d565efSmrg@code{@@finally} and @code{@@synchronized}) is
28110d565efSmrgsupported by GCC and is enabled with the option
28210d565efSmrg@option{-fobjc-exceptions}.  The syntax is briefly documented in this
28310d565efSmrgmanual and in the Objective-C 2.0 manuals from Apple.
28410d565efSmrg
28510d565efSmrgThe Objective-C 2.0 language extensions and features are automatically
28610d565efSmrgenabled; they include properties (via the @code{@@property},
28710d565efSmrg@code{@@synthesize} and
28810d565efSmrg@code{@@dynamic keywords}), fast enumeration (not available in
28910d565efSmrgObjective-C++), attributes for methods (such as @code{deprecated},
29010d565efSmrg@code{noreturn}, @code{sentinel}, @code{format}),
29110d565efSmrgthe @code{unused} attribute for method arguments, the
29210d565efSmrg@code{@@package} keyword for instance variables and the @code{@@optional} and
29310d565efSmrg@code{@@required} keywords in protocols.  You can disable all these
29410d565efSmrgObjective-C 2.0 language extensions with the option
29510d565efSmrg@option{-fobjc-std=objc1}, which causes the compiler to recognize the
29610d565efSmrgsame Objective-C language syntax recognized by GCC 4.0, and to produce
29710d565efSmrgan error if one of the new features is used.
29810d565efSmrg
29910d565efSmrgGCC has currently no support for non-fragile instance variables.
30010d565efSmrg
30110d565efSmrgThe authoritative manual on Objective-C 2.0 is available from Apple:
30210d565efSmrg@itemize
30310d565efSmrg@item
3040fc04c29Smrg@uref{https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html}
30510d565efSmrg@end itemize
30610d565efSmrg
30710d565efSmrgFor more information concerning the history of Objective-C that is
30810d565efSmrgavailable online, see @uref{http://gcc.gnu.org/readings.html}
30910d565efSmrg
31010d565efSmrg@section Go Language
31110d565efSmrg
31210d565efSmrgAs of the GCC 4.7.1 release, GCC supports the Go 1 language standard,
31310d565efSmrgdescribed at @uref{https://golang.org/doc/go1}.
31410d565efSmrg
31510d565efSmrg@section HSA Intermediate Language (HSAIL)
31610d565efSmrg
31710d565efSmrgGCC can compile the binary representation (BRIG) of the HSAIL text format as
31810d565efSmrgdescribed in HSA Programmer's Reference Manual version 1.0.1. This
31910d565efSmrgcapability is typically utilized to implement the HSA runtime API's HSAIL
32010d565efSmrgfinalization extension for a gcc supported processor. HSA standards are
32110d565efSmrgfreely available at @uref{http://www.hsafoundation.com/standards/}.
32210d565efSmrg
3230fc04c29Smrg@section D language
3240fc04c29Smrg
3250fc04c29SmrgGCC supports the D 2.0 programming language.  The D language itself is
3260fc04c29Smrgcurrently defined by its reference implementation and supporting language
3270fc04c29Smrgspecification, described at @uref{https://dlang.org/spec/spec.html}.
3280fc04c29Smrg
32910d565efSmrg@section References for Other Languages
33010d565efSmrg
33110d565efSmrg@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
33210d565efSmrgGNAT Reference Manual}, for information on standard
33310d565efSmrgconformance and compatibility of the Ada compiler.
33410d565efSmrg
33510d565efSmrg@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details
33610d565efSmrgof standards supported by GNU Fortran.
337