]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/standards.texi
Update copyright years.
[thirdparty/gcc.git] / gcc / doc / standards.texi
CommitLineData
8d9254fc 1@c Copyright (C) 2000-2020 Free Software Foundation, Inc.
b64a6a11
JM
2@c This is part of the GCC manual.
3@c For copying conditions, see the file gcc.texi.
4
5@node Standards
6@chapter Language Standards Supported by GCC
fda0adca
DG
7
8For each language compiled by GCC for which there is a standard, GCC
9attempts to follow one or more versions of that standard, possibly
10with some exceptions, and possibly with some extensions.
11
e6f3f526 12@section C Language
b64a6a11
JM
13@cindex C standard
14@cindex C standards
15@cindex ANSI C standard
16@cindex ANSI C
17@cindex ANSI C89
18@cindex C89
19@cindex ANSI X3.159-1989
20@cindex X3.159-1989
21@cindex ISO C standard
22@cindex ISO C
b64a6a11
JM
23@cindex ISO C90
24@cindex ISO/IEC 9899
25@cindex ISO 9899
26@cindex C90
27@cindex ISO C94
28@cindex C94
29@cindex ISO C95
30@cindex C95
31@cindex ISO C99
32@cindex C99
33@cindex ISO C9X
34@cindex C9X
48b0b196
JM
35@cindex ISO C11
36@cindex C11
2778d766
JM
37@cindex ISO C1X
38@cindex C1X
c76dc9c3
JM
39@cindex ISO C17
40@cindex C17
9f936c86
JM
41@cindex ISO C2X
42@cindex C2X
b64a6a11
JM
43@cindex Technical Corrigenda
44@cindex TC1
45@cindex Technical Corrigendum 1
46@cindex TC2
47@cindex Technical Corrigendum 2
6ac0194d
JM
48@cindex TC3
49@cindex Technical Corrigendum 3
b64a6a11
JM
50@cindex AMD1
51@cindex freestanding implementation
52@cindex freestanding environment
53@cindex hosted implementation
54@cindex hosted environment
55@findex __STDC_HOSTED__
56
b64a6a11
JM
57@opindex std
58@opindex ansi
59@opindex pedantic
60@opindex pedantic-errors
61The original ANSI C standard (X3.159-1989) was ratified in 1989 and
62published in 1990. This standard was ratified as an ISO standard
63(ISO/IEC 9899:1990) later in 1990. There were no technical
64differences between these publications, although the sections of the
65ANSI standard were renumbered and became clauses in the ISO standard.
d0899488 66The ANSI
b64a6a11 67standard, but not the ISO standard, also came with a Rationale
d0899488
SL
68document.
69This standard, in both its forms, is commonly known as @dfn{C89}, or
70occasionally as @dfn{C90}, from the dates of ratification.
71To select this standard in GCC, use one of the options
7e1542b9 72@option{-ansi}, @option{-std=c90} or @option{-std=iso9899:1990}; to obtain
b64a6a11
JM
73all the diagnostics required by the standard, you should also specify
74@option{-pedantic} (or @option{-pedantic-errors} if you want them to be
75errors rather than warnings). @xref{C Dialect Options,,Options
76Controlling C Dialect}.
77
78Errors in the 1990 ISO C standard were corrected in two Technical
79Corrigenda published in 1994 and 1996. GCC does not support the
80uncorrected version.
81
82An amendment to the 1990 standard was published in 1995. This
83amendment added digraphs and @code{__STDC_VERSION__} to the language,
84but otherwise concerned the library. This amendment is commonly known
85as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
86@dfn{C95}. To select this standard in GCC, use the option
87@option{-std=iso9899:199409} (with, as for other standard versions,
88@option{-pedantic} to receive all required diagnostics).
89
90A new edition of the ISO C standard was published in 1999 as ISO/IEC
d0899488
SL
919899:1999, and is commonly known as @dfn{C99}. (While in
92development, drafts of this standard version were referred to as
93@dfn{C9X}.) GCC has substantially
b76f5d16 94complete support for this standard version; see
b64a6a11 95@uref{http://gcc.gnu.org/c99status.html} for details. To select this
d0899488 96standard, use @option{-std=c99} or @option{-std=iso9899:1999}.
b64a6a11 97
6ac0194d
JM
98Errors in the 1999 ISO C standard were corrected in three Technical
99Corrigenda published in 2001, 2004 and 2007. GCC does not support the
100uncorrected version.
222bde43 101
48b0b196 102A fourth version of the C standard, known as @dfn{C11}, was published
d0899488 103in 2011 as ISO/IEC 9899:2011. (While in development, drafts of this
48b0b196 104standard version were referred to as @dfn{C1X}.)
d0899488
SL
105GCC has substantially complete support
106for this standard, enabled with @option{-std=c11} or
7dc41f3d
JM
107@option{-std=iso9899:2011}. A version with corrections integrated was
108prepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it is
c76dc9c3
JM
109known as @dfn{C17} and is supported with @option{-std=c17} or
110@option{-std=iso9899:2017}; the corrections are also applied with
111@option{-std=c11}, and the only difference between the options is the
112value of @code{__STDC_VERSION__}.
2778d766 113
9f936c86
JM
114A further version of the C standard, known as @dfn{C2X}, is under
115development; experimental and incomplete support for this is enabled
116with @option{-std=c2x}.
117
d0899488 118By default, GCC provides some extensions to the C language that, on
b64a6a11 119rare occasions conflict with the C standard. @xref{C
d0899488
SL
120Extensions,,Extensions to the C Language Family}.
121Some features that are part of the C99 standard
122are accepted as extensions in C90 mode, and some features that are part
123of the C11 standard are accepted as extensions in C90 and C99 modes.
124Use of the
36d421ec 125@option{-std} options listed above disables these extensions where
b64a6a11
JM
126they conflict with the C standard version selected. You may also
127select an extended version of the C language explicitly with
2778d766 128@option{-std=gnu90} (for C90 with GNU extensions), @option{-std=gnu99}
48b0b196 129(for C99 with GNU extensions) or @option{-std=gnu11} (for C11 with GNU
d0899488
SL
130extensions).
131
132The default, if no C language dialect options are given,
133is @option{-std=gnu11}.
b64a6a11
JM
134
135The ISO C standard defines (in clause 4) two classes of conforming
136implementation. A @dfn{conforming hosted implementation} supports the
137whole standard including all the library facilities; a @dfn{conforming
138freestanding implementation} is only required to provide certain
139library facilities: those in @code{<float.h>}, @code{<limits.h>},
140@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
48b0b196
JM
141@code{<iso646.h>}; since C99, also those in @code{<stdbool.h>} and
142@code{<stdint.h>}; and since C11, also those in @code{<stdalign.h>}
143and @code{<stdnoreturn.h>}. In addition, complex types, added in C99, are not
d0899488
SL
144required for freestanding implementations.
145
146The standard also defines two environments for programs, a
147@dfn{freestanding environment}, required of all implementations and
148which may not have library facilities beyond those required of
149freestanding implementations, where the handling of program startup
150and termination are implementation-defined; and a @dfn{hosted
151environment}, which is not required, in which all the library
152facilities are provided and startup is through a function @code{int
153main (void)} or @code{int main (int, char *[])}. An OS kernel is an example
154of a program running in a freestanding environment;
155a program using the facilities of an
156operating system is an example of a program running in a hosted environment.
b64a6a11
JM
157
158@opindex ffreestanding
159GCC aims towards being usable as a conforming freestanding
160implementation, or as the compiler for a conforming hosted
d0899488 161implementation. By default, it acts as the compiler for a hosted
b64a6a11
JM
162implementation, defining @code{__STDC_HOSTED__} as @code{1} and
163presuming that when the names of ISO C functions are used, they have
164the semantics defined in the standard. To make it act as a conforming
165freestanding implementation for a freestanding environment, use the
d0899488
SL
166option @option{-ffreestanding}; it then defines
167@code{__STDC_HOSTED__} to @code{0} and does not make assumptions about the
3a079822
RH
168meanings of function names from the standard library, with exceptions
169noted below. To build an OS kernel, you may well still need to make
170your own arrangements for linking and startup.
171@xref{C Dialect Options,,Options Controlling C Dialect}.
b64a6a11
JM
172
173GCC does not provide the library facilities required only of hosted
174implementations, nor yet all the facilities required by C99 of
d0899488
SL
175freestanding implementations on all platforms.
176To use the facilities of a hosted
177environment, you need to find them elsewhere (for example, in the
b64a6a11
JM
178GNU C library). @xref{Standard Libraries,,Standard Libraries}.
179
3a079822
RH
180Most of the compiler support routines used by GCC are present in
181@file{libgcc}, but there are a few exceptions. GCC requires the
182freestanding environment provide @code{memcpy}, @code{memmove},
8f99553f 183@code{memset} and @code{memcmp}.
daf2f129 184Finally, if @code{__builtin_trap} is used, and the target does
d0899488 185not implement the @code{trap} pattern, then GCC emits a call
3a079822
RH
186to @code{abort}.
187
b64a6a11
JM
188For references to Technical Corrigenda, Rationale documents and
189information concerning the history of C that is available online, see
190@uref{http://gcc.gnu.org/readings.html}
191
e6f3f526 192@section C++ Language
fda0adca 193
36d421ec
JW
194GCC supports the original ISO C++ standard published in 1998,
195and the 2011 and 2014 revisions.
fda0adca
DG
196
197The original ISO C++ standard was published as the ISO standard (ISO/IEC
19814882:1998) and amended by a Technical Corrigenda published in 2003
199(ISO/IEC 14882:2003). These standards are referred to as C++98 and
200C++03, respectively. GCC implements the majority of C++98 (@code{export}
201is a notable exception) and most of the changes in C++03. To select
e2c4d88e
JM
202this standard in GCC, use one of the options @option{-ansi},
203@option{-std=c++98}, or @option{-std=c++03}; to obtain all the diagnostics
204required by the standard, you should also specify @option{-pedantic} (or
fda0adca
DG
205@option{-pedantic-errors} if you want them to be errors rather than
206warnings).
207
e2c4d88e
JM
208A revised ISO C++ standard was published in 2011 as ISO/IEC
20914882:2011, and is referred to as C++11; before its publication it was
36d421ec
JW
210commonly referred to as C++0x. C++11 contains several changes to the
211C++ language, all of which have been implemented in GCC@. For details
39ebef2c 212see @uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx11}.
36d421ec
JW
213To select this standard in GCC, use the option @option{-std=c++11}.
214
215Another revised ISO C++ standard was published in 2014 as ISO/IEC
21614882:2014, and is referred to as C++14; before its publication it was
217sometimes referred to as C++1y. C++14 contains several further
218changes to the C++ language, all of which have been implemented in GCC@.
39ebef2c 219For details see @uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx14}.
36d421ec
JW
220To select this standard in GCC, use the option @option{-std=c++14}.
221
39ebef2c
NS
222The C++ language was further revised in 2017 and ISO/IEC 14882:2017 was
223published. This is referred to as C++17, and before publication was
224often referred to as C++1z. GCC supports all the changes in the new
225specification. For further details see
226@uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx1z}. Use the option
227@option{-std=c++17} to select this variant of C++.
e2c4d88e
JM
228
229More information about the C++ standards is available on the ISO C++
230committee's web site at @uref{http://www.open-std.org/@/jtc1/@/sc22/@/wg21/}.
fda0adca 231
36d421ec
JW
232To obtain all the diagnostics required by any of the standard versions
233described above you should specify @option{-pedantic}
234or @option{-pedantic-errors}, otherwise GCC will allow some non-ISO C++
235features as extensions. @xref{Warning Options}.
236
237By default, GCC also provides some additional extensions to the C++ language
238that on rare occasions conflict with the C++ standard. @xref{C++
fda0adca 239Dialect Options,Options Controlling C++ Dialect}. Use of the
36d421ec
JW
240@option{-std} options listed above disables these extensions where they
241they conflict with the C++ standard version selected. You may also
242select an extended version of the C++ language explicitly with
243@option{-std=gnu++98} (for C++98 with GNU extensions), or
244@option{-std=gnu++11} (for C++11 with GNU extensions), or
245@option{-std=gnu++14} (for C++14 with GNU extensions), or
39ebef2c 246@option{-std=gnu++17} (for C++17 with GNU extensions).
d0899488
SL
247
248The default, if
36d421ec 249no C++ language dialect options are given, is @option{-std=gnu++14}.
b64a6a11 250
e6f3f526 251@section Objective-C and Objective-C++ Languages
46e34f96
ZL
252@cindex Objective-C
253@cindex Objective-C++
254
6b79b1b7 255GCC supports ``traditional'' Objective-C (also known as ``Objective-C
22d8d616
NP
2561.0'') and contains support for the Objective-C exception and
257synchronization syntax. It has also support for a number of
258``Objective-C 2.0'' language extensions, including properties, fast
259enumeration (only for Objective-C), method attributes and the
260@@optional and @@required keywords in protocols. GCC supports
261Objective-C++ and features available in Objective-C are also available
262in Objective-C++@.
478c9e72 263
6b79b1b7
NP
264GCC by default uses the GNU Objective-C runtime library, which is part
265of GCC and is not the same as the Apple/NeXT Objective-C runtime
266library used on Apple systems. There are a number of differences
267documented in this manual. The options @option{-fgnu-runtime} and
268@option{-fnext-runtime} allow you to switch between producing output
269that works with the GNU Objective-C runtime library and output that
270works with the Apple/NeXT Objective-C runtime library.
271
272There is no formal written standard for Objective-C or Objective-C++@.
273The authoritative manual on traditional Objective-C (1.0) is
d0899488 274``Object-Oriented Programming and the Objective-C Language'':
6b79b1b7 275@uref{http://www.gnustep.org/@/resources/@/documentation/@/ObjectivCBook.pdf}
54aecc5a 276is the original NeXTstep document.
b64a6a11 277
6b79b1b7 278The Objective-C exception and synchronization syntax (that is, the
d0899488
SL
279keywords @code{@@try}, @code{@@throw}, @code{@@catch},
280@code{@@finally} and @code{@@synchronized}) is
22d8d616 281supported by GCC and is enabled with the option
6b79b1b7
NP
282@option{-fobjc-exceptions}. The syntax is briefly documented in this
283manual and in the Objective-C 2.0 manuals from Apple.
284
22d8d616 285The Objective-C 2.0 language extensions and features are automatically
d0899488
SL
286enabled; they include properties (via the @code{@@property},
287@code{@@synthesize} and
288@code{@@dynamic keywords}), fast enumeration (not available in
289Objective-C++), attributes for methods (such as @code{deprecated},
290@code{noreturn}, @code{sentinel}, @code{format}),
291the @code{unused} attribute for method arguments, the
292@code{@@package} keyword for instance variables and the @code{@@optional} and
293@code{@@required} keywords in protocols. You can disable all these
22d8d616
NP
294Objective-C 2.0 language extensions with the option
295@option{-fobjc-std=objc1}, which causes the compiler to recognize the
296same Objective-C language syntax recognized by GCC 4.0, and to produce
297an error if one of the new features is used.
298
299GCC has currently no support for non-fragile instance variables.
300
301The authoritative manual on Objective-C 2.0 is available from Apple:
6b79b1b7
NP
302@itemize
303@item
2b35b704 304@uref{https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html}
6b79b1b7
NP
305@end itemize
306
307For more information concerning the history of Objective-C that is
308available online, see @uref{http://gcc.gnu.org/readings.html}
309
e6f3f526 310@section Go Language
7a938933 311
526c230f 312As of the GCC 4.7.1 release, GCC supports the Go 1 language standard,
e2f09737 313described at @uref{https://golang.org/doc/go1}.
7a938933 314
5fd1486c
PJ
315@section HSA Intermediate Language (HSAIL)
316
317GCC can compile the binary representation (BRIG) of the HSAIL text format as
318described in HSA Programmer's Reference Manual version 1.0.1. This
319capability is typically utilized to implement the HSA runtime API's HSAIL
320finalization extension for a gcc supported processor. HSA standards are
321freely available at @uref{http://www.hsafoundation.com/standards/}.
322
b4c522fa
IB
323@section D language
324
325GCC supports the D 2.0 programming language. The D language itself is
326currently defined by its reference implementation and supporting language
327specification, described at @uref{https://dlang.org/spec/spec.html}.
328
e6f3f526 329@section References for Other Languages
7a938933 330
f282ffb3 331@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
b64a6a11
JM
332GNAT Reference Manual}, for information on standard
333conformance and compatibility of the Ada compiler.
334
92922512
BM
335@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details
336of standards supported by GNU Fortran.