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