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