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