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