1*e4b17023SJohn Marino@c Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007, 2008, 2010
2*e4b17023SJohn Marino@c Free Software Foundation, Inc.
3*e4b17023SJohn Marino@c This is part of the GCC manual.
4*e4b17023SJohn Marino@c For copying conditions, see the file gcc.texi.
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino@node Standards
7*e4b17023SJohn Marino@chapter Language Standards Supported by GCC
8*e4b17023SJohn Marino
9*e4b17023SJohn MarinoFor each language compiled by GCC for which there is a standard, GCC
10*e4b17023SJohn Marinoattempts to follow one or more versions of that standard, possibly
11*e4b17023SJohn Marinowith some exceptions, and possibly with some extensions.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino@section C language
14*e4b17023SJohn Marino@cindex C standard
15*e4b17023SJohn Marino@cindex C standards
16*e4b17023SJohn Marino@cindex ANSI C standard
17*e4b17023SJohn Marino@cindex ANSI C
18*e4b17023SJohn Marino@cindex ANSI C89
19*e4b17023SJohn Marino@cindex C89
20*e4b17023SJohn Marino@cindex ANSI X3.159-1989
21*e4b17023SJohn Marino@cindex X3.159-1989
22*e4b17023SJohn Marino@cindex ISO C standard
23*e4b17023SJohn Marino@cindex ISO C
24*e4b17023SJohn Marino@cindex ISO C90
25*e4b17023SJohn Marino@cindex ISO/IEC 9899
26*e4b17023SJohn Marino@cindex ISO 9899
27*e4b17023SJohn Marino@cindex C90
28*e4b17023SJohn Marino@cindex ISO C94
29*e4b17023SJohn Marino@cindex C94
30*e4b17023SJohn Marino@cindex ISO C95
31*e4b17023SJohn Marino@cindex C95
32*e4b17023SJohn Marino@cindex ISO C99
33*e4b17023SJohn Marino@cindex C99
34*e4b17023SJohn Marino@cindex ISO C9X
35*e4b17023SJohn Marino@cindex C9X
36*e4b17023SJohn Marino@cindex ISO C11
37*e4b17023SJohn Marino@cindex C11
38*e4b17023SJohn Marino@cindex ISO C1X
39*e4b17023SJohn Marino@cindex C1X
40*e4b17023SJohn Marino@cindex Technical Corrigenda
41*e4b17023SJohn Marino@cindex TC1
42*e4b17023SJohn Marino@cindex Technical Corrigendum 1
43*e4b17023SJohn Marino@cindex TC2
44*e4b17023SJohn Marino@cindex Technical Corrigendum 2
45*e4b17023SJohn Marino@cindex TC3
46*e4b17023SJohn Marino@cindex Technical Corrigendum 3
47*e4b17023SJohn Marino@cindex AMD1
48*e4b17023SJohn Marino@cindex freestanding implementation
49*e4b17023SJohn Marino@cindex freestanding environment
50*e4b17023SJohn Marino@cindex hosted implementation
51*e4b17023SJohn Marino@cindex hosted environment
52*e4b17023SJohn Marino@findex __STDC_HOSTED__
53*e4b17023SJohn Marino
54*e4b17023SJohn MarinoGCC supports three versions of the C standard, although support for
55*e4b17023SJohn Marinothe most recent version is not yet complete.
56*e4b17023SJohn Marino
57*e4b17023SJohn Marino@opindex std
58*e4b17023SJohn Marino@opindex ansi
59*e4b17023SJohn Marino@opindex pedantic
60*e4b17023SJohn Marino@opindex pedantic-errors
61*e4b17023SJohn MarinoThe original ANSI C standard (X3.159-1989) was ratified in 1989 and
62*e4b17023SJohn Marinopublished in 1990.  This standard was ratified as an ISO standard
63*e4b17023SJohn Marino(ISO/IEC 9899:1990) later in 1990.  There were no technical
64*e4b17023SJohn Marinodifferences between these publications, although the sections of the
65*e4b17023SJohn MarinoANSI standard were renumbered and became clauses in the ISO standard.
66*e4b17023SJohn MarinoThis standard, in both its forms, is commonly known as @dfn{C89}, or
67*e4b17023SJohn Marinooccasionally as @dfn{C90}, from the dates of ratification.  The ANSI
68*e4b17023SJohn Marinostandard, but not the ISO standard, also came with a Rationale
69*e4b17023SJohn Marinodocument.  To select this standard in GCC, use one of the options
70*e4b17023SJohn Marino@option{-ansi}, @option{-std=c90} or @option{-std=iso9899:1990}; to obtain
71*e4b17023SJohn Marinoall the diagnostics required by the standard, you should also specify
72*e4b17023SJohn Marino@option{-pedantic} (or @option{-pedantic-errors} if you want them to be
73*e4b17023SJohn Marinoerrors rather than warnings).  @xref{C Dialect Options,,Options
74*e4b17023SJohn MarinoControlling C Dialect}.
75*e4b17023SJohn Marino
76*e4b17023SJohn MarinoErrors in the 1990 ISO C standard were corrected in two Technical
77*e4b17023SJohn MarinoCorrigenda published in 1994 and 1996.  GCC does not support the
78*e4b17023SJohn Marinouncorrected version.
79*e4b17023SJohn Marino
80*e4b17023SJohn MarinoAn amendment to the 1990 standard was published in 1995.  This
81*e4b17023SJohn Marinoamendment added digraphs and @code{__STDC_VERSION__} to the language,
82*e4b17023SJohn Marinobut otherwise concerned the library.  This amendment is commonly known
83*e4b17023SJohn Marinoas @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
84*e4b17023SJohn Marino@dfn{C95}.  To select this standard in GCC, use the option
85*e4b17023SJohn Marino@option{-std=iso9899:199409} (with, as for other standard versions,
86*e4b17023SJohn Marino@option{-pedantic} to receive all required diagnostics).
87*e4b17023SJohn Marino
88*e4b17023SJohn MarinoA new edition of the ISO C standard was published in 1999 as ISO/IEC
89*e4b17023SJohn Marino9899:1999, and is commonly known as @dfn{C99}.  GCC has incomplete
90*e4b17023SJohn Marinosupport for this standard version; see
91*e4b17023SJohn Marino@uref{http://gcc.gnu.org/gcc-4.7/c99status.html} for details.  To select this
92*e4b17023SJohn Marinostandard, use @option{-std=c99} or @option{-std=iso9899:1999}.  (While in
93*e4b17023SJohn Marinodevelopment, drafts of this standard version were referred to as
94*e4b17023SJohn Marino@dfn{C9X}.)
95*e4b17023SJohn Marino
96*e4b17023SJohn MarinoErrors in the 1999 ISO C standard were corrected in three Technical
97*e4b17023SJohn MarinoCorrigenda published in 2001, 2004 and 2007.  GCC does not support the
98*e4b17023SJohn Marinouncorrected version.
99*e4b17023SJohn Marino
100*e4b17023SJohn MarinoA fourth version of the C standard, known as @dfn{C11}, was published
101*e4b17023SJohn Marinoin 2011 as ISO/IEC 9899:2011.  GCC has limited incomplete support for
102*e4b17023SJohn Marinoparts of this standard, enabled with @option{-std=c11} or
103*e4b17023SJohn Marino@option{-std=iso9899:2011}.  (While in development, drafts of this
104*e4b17023SJohn Marinostandard version were referred to as @dfn{C1X}.)
105*e4b17023SJohn Marino
106*e4b17023SJohn MarinoBy default, GCC provides some extensions to the C language that on
107*e4b17023SJohn Marinorare occasions conflict with the C standard.  @xref{C
108*e4b17023SJohn MarinoExtensions,,Extensions to the C Language Family}.  Use of the
109*e4b17023SJohn Marino@option{-std} options listed above will disable these extensions where
110*e4b17023SJohn Marinothey conflict with the C standard version selected.  You may also
111*e4b17023SJohn Marinoselect an extended version of the C language explicitly with
112*e4b17023SJohn Marino@option{-std=gnu90} (for C90 with GNU extensions), @option{-std=gnu99}
113*e4b17023SJohn Marino(for C99 with GNU extensions) or @option{-std=gnu11} (for C11 with GNU
114*e4b17023SJohn Marinoextensions).  The default, if no C language dialect
115*e4b17023SJohn Marinooptions are given, is @option{-std=gnu90}; this will change to
116*e4b17023SJohn Marino@option{-std=gnu99} or @option{-std=gnu11} in some future release when
117*e4b17023SJohn Marinothe C99 or C11 support is
118*e4b17023SJohn Marinocomplete.  Some features that are part of the C99 standard are
119*e4b17023SJohn Marinoaccepted as extensions in C90 mode, and some features that are part of
120*e4b17023SJohn Marinothe C11 standard are accepted as extensions in C90 and C99 modes.
121*e4b17023SJohn Marino
122*e4b17023SJohn MarinoThe ISO C standard defines (in clause 4) two classes of conforming
123*e4b17023SJohn Marinoimplementation.  A @dfn{conforming hosted implementation} supports the
124*e4b17023SJohn Marinowhole standard including all the library facilities; a @dfn{conforming
125*e4b17023SJohn Marinofreestanding implementation} is only required to provide certain
126*e4b17023SJohn Marinolibrary facilities: those in @code{<float.h>}, @code{<limits.h>},
127*e4b17023SJohn Marino@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
128*e4b17023SJohn Marino@code{<iso646.h>}; since C99, also those in @code{<stdbool.h>} and
129*e4b17023SJohn Marino@code{<stdint.h>}; and since C11, also those in @code{<stdalign.h>}
130*e4b17023SJohn Marinoand @code{<stdnoreturn.h>}.  In addition, complex types, added in C99, are not
131*e4b17023SJohn Marinorequired for freestanding implementations.  The standard also defines
132*e4b17023SJohn Marinotwo environments for programs, a @dfn{freestanding environment},
133*e4b17023SJohn Marinorequired of all implementations and which may not have library
134*e4b17023SJohn Marinofacilities beyond those required of freestanding implementations,
135*e4b17023SJohn Marinowhere the handling of program startup and termination are
136*e4b17023SJohn Marinoimplementation-defined, and a @dfn{hosted environment}, which is not
137*e4b17023SJohn Marinorequired, in which all the library facilities are provided and startup
138*e4b17023SJohn Marinois through a function @code{int main (void)} or @code{int main (int,
139*e4b17023SJohn Marinochar *[])}.  An OS kernel would be a freestanding environment; a
140*e4b17023SJohn Marinoprogram using the facilities of an operating system would normally be
141*e4b17023SJohn Marinoin a hosted implementation.
142*e4b17023SJohn Marino
143*e4b17023SJohn Marino@opindex ffreestanding
144*e4b17023SJohn MarinoGCC aims towards being usable as a conforming freestanding
145*e4b17023SJohn Marinoimplementation, or as the compiler for a conforming hosted
146*e4b17023SJohn Marinoimplementation.  By default, it will act as the compiler for a hosted
147*e4b17023SJohn Marinoimplementation, defining @code{__STDC_HOSTED__} as @code{1} and
148*e4b17023SJohn Marinopresuming that when the names of ISO C functions are used, they have
149*e4b17023SJohn Marinothe semantics defined in the standard.  To make it act as a conforming
150*e4b17023SJohn Marinofreestanding implementation for a freestanding environment, use the
151*e4b17023SJohn Marinooption @option{-ffreestanding}; it will then define
152*e4b17023SJohn Marino@code{__STDC_HOSTED__} to @code{0} and not make assumptions about the
153*e4b17023SJohn Marinomeanings of function names from the standard library, with exceptions
154*e4b17023SJohn Marinonoted below.  To build an OS kernel, you may well still need to make
155*e4b17023SJohn Marinoyour own arrangements for linking and startup.
156*e4b17023SJohn Marino@xref{C Dialect Options,,Options Controlling C Dialect}.
157*e4b17023SJohn Marino
158*e4b17023SJohn MarinoGCC does not provide the library facilities required only of hosted
159*e4b17023SJohn Marinoimplementations, nor yet all the facilities required by C99 of
160*e4b17023SJohn Marinofreestanding implementations; to use the facilities of a hosted
161*e4b17023SJohn Marinoenvironment, you will need to find them elsewhere (for example, in the
162*e4b17023SJohn MarinoGNU C library).  @xref{Standard Libraries,,Standard Libraries}.
163*e4b17023SJohn Marino
164*e4b17023SJohn MarinoMost of the compiler support routines used by GCC are present in
165*e4b17023SJohn Marino@file{libgcc}, but there are a few exceptions.  GCC requires the
166*e4b17023SJohn Marinofreestanding environment provide @code{memcpy}, @code{memmove},
167*e4b17023SJohn Marino@code{memset} and @code{memcmp}.
168*e4b17023SJohn MarinoFinally, if @code{__builtin_trap} is used, and the target does
169*e4b17023SJohn Marinonot implement the @code{trap} pattern, then GCC will emit a call
170*e4b17023SJohn Marinoto @code{abort}.
171*e4b17023SJohn Marino
172*e4b17023SJohn MarinoFor references to Technical Corrigenda, Rationale documents and
173*e4b17023SJohn Marinoinformation concerning the history of C that is available online, see
174*e4b17023SJohn Marino@uref{http://gcc.gnu.org/readings.html}
175*e4b17023SJohn Marino
176*e4b17023SJohn Marino@section C++ language
177*e4b17023SJohn Marino
178*e4b17023SJohn MarinoGCC supports the original ISO C++ standard (1998) and contains
179*e4b17023SJohn Marinoexperimental support for the second ISO C++ standard (2011).
180*e4b17023SJohn Marino
181*e4b17023SJohn MarinoThe original ISO C++ standard was published as the ISO standard (ISO/IEC
182*e4b17023SJohn Marino14882:1998) and amended by a Technical Corrigenda published in 2003
183*e4b17023SJohn Marino(ISO/IEC 14882:2003). These standards are referred to as C++98 and
184*e4b17023SJohn MarinoC++03, respectively. GCC implements the majority of C++98 (@code{export}
185*e4b17023SJohn Marinois a notable exception) and most of the changes in C++03.  To select
186*e4b17023SJohn Marinothis standard in GCC, use one of the options @option{-ansi},
187*e4b17023SJohn Marino@option{-std=c++98}, or @option{-std=c++03}; to obtain all the diagnostics
188*e4b17023SJohn Marinorequired by the standard, you should also specify @option{-pedantic} (or
189*e4b17023SJohn Marino@option{-pedantic-errors} if you want them to be errors rather than
190*e4b17023SJohn Marinowarnings).
191*e4b17023SJohn Marino
192*e4b17023SJohn MarinoA revised ISO C++ standard was published in 2011 as ISO/IEC
193*e4b17023SJohn Marino14882:2011, and is referred to as C++11; before its publication it was
194*e4b17023SJohn Marinocommonly referred to as C++0x.  C++11 contains several
195*e4b17023SJohn Marinochanges to the C++ language, most of which have been implemented in an
196*e4b17023SJohn Marinoexperimental C++11 mode in GCC@.  For information
197*e4b17023SJohn Marinoregarding the C++11 features available in the experimental C++11 mode,
198*e4b17023SJohn Marinosee @uref{http://gcc.gnu.org/projects/@/cxx0x.html}. To select this
199*e4b17023SJohn Marinostandard in GCC, use the option @option{-std=c++11}; to obtain all the
200*e4b17023SJohn Marinodiagnostics required by the standard, you should also specify
201*e4b17023SJohn Marino@option{-pedantic} (or @option{-pedantic-errors} if you want them to
202*e4b17023SJohn Marinobe errors rather than warnings).
203*e4b17023SJohn Marino
204*e4b17023SJohn MarinoMore information about the C++ standards is available on the ISO C++
205*e4b17023SJohn Marinocommittee's web site at @uref{http://www.open-std.org/@/jtc1/@/sc22/@/wg21/}.
206*e4b17023SJohn Marino
207*e4b17023SJohn MarinoBy default, GCC provides some extensions to the C++ language; @xref{C++
208*e4b17023SJohn MarinoDialect Options,Options Controlling C++ Dialect}.  Use of the
209*e4b17023SJohn Marino@option{-std} option listed above will disable these extensions.  You
210*e4b17023SJohn Marinomay also select an extended version of the C++ language explicitly with
211*e4b17023SJohn Marino@option{-std=gnu++98} (for C++98 with GNU extensions) or
212*e4b17023SJohn Marino@option{-std=gnu++11} (for C++11 with GNU extensions).  The default, if
213*e4b17023SJohn Marinono C++ language dialect options are given, is @option{-std=gnu++98}.
214*e4b17023SJohn Marino
215*e4b17023SJohn Marino@section Objective-C and Objective-C++ languages
216*e4b17023SJohn Marino@cindex Objective-C
217*e4b17023SJohn Marino@cindex Objective-C++
218*e4b17023SJohn Marino
219*e4b17023SJohn MarinoGCC supports ``traditional'' Objective-C (also known as ``Objective-C
220*e4b17023SJohn Marino1.0'') and contains support for the Objective-C exception and
221*e4b17023SJohn Marinosynchronization syntax.  It has also support for a number of
222*e4b17023SJohn Marino``Objective-C 2.0'' language extensions, including properties, fast
223*e4b17023SJohn Marinoenumeration (only for Objective-C), method attributes and the
224*e4b17023SJohn Marino@@optional and @@required keywords in protocols.  GCC supports
225*e4b17023SJohn MarinoObjective-C++ and features available in Objective-C are also available
226*e4b17023SJohn Marinoin Objective-C++@.
227*e4b17023SJohn Marino
228*e4b17023SJohn MarinoGCC by default uses the GNU Objective-C runtime library, which is part
229*e4b17023SJohn Marinoof GCC and is not the same as the Apple/NeXT Objective-C runtime
230*e4b17023SJohn Marinolibrary used on Apple systems.  There are a number of differences
231*e4b17023SJohn Marinodocumented in this manual.  The options @option{-fgnu-runtime} and
232*e4b17023SJohn Marino@option{-fnext-runtime} allow you to switch between producing output
233*e4b17023SJohn Marinothat works with the GNU Objective-C runtime library and output that
234*e4b17023SJohn Marinoworks with the Apple/NeXT Objective-C runtime library.
235*e4b17023SJohn Marino
236*e4b17023SJohn MarinoThere is no formal written standard for Objective-C or Objective-C++@.
237*e4b17023SJohn MarinoThe authoritative manual on traditional Objective-C (1.0) is
238*e4b17023SJohn Marino``Object-Oriented Programming and the Objective-C Language'',
239*e4b17023SJohn Marinoavailable at a number of web sites:
240*e4b17023SJohn Marino@itemize
241*e4b17023SJohn Marino@item
242*e4b17023SJohn Marino@uref{http://www.gnustep.org/@/resources/@/documentation/@/ObjectivCBook.pdf}
243*e4b17023SJohn Marinois the original NeXTstep document;
244*e4b17023SJohn Marino@item
245*e4b17023SJohn Marino@uref{http://objc.toodarkpark.net}
246*e4b17023SJohn Marinois the same document in another format;
247*e4b17023SJohn Marino@item
248*e4b17023SJohn Marino@uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/}
249*e4b17023SJohn Marinohas an updated version but make sure you search for ``Object Oriented Programming and the Objective-C Programming Language 1.0'',
250*e4b17023SJohn Marinonot documentation on the newer ``Objective-C 2.0'' language
251*e4b17023SJohn Marino@end itemize
252*e4b17023SJohn Marino
253*e4b17023SJohn MarinoThe Objective-C exception and synchronization syntax (that is, the
254*e4b17023SJohn Marinokeywords @@try, @@throw, @@catch, @@finally and @@synchronized) is
255*e4b17023SJohn Marinosupported by GCC and is enabled with the option
256*e4b17023SJohn Marino@option{-fobjc-exceptions}.  The syntax is briefly documented in this
257*e4b17023SJohn Marinomanual and in the Objective-C 2.0 manuals from Apple.
258*e4b17023SJohn Marino
259*e4b17023SJohn MarinoThe Objective-C 2.0 language extensions and features are automatically
260*e4b17023SJohn Marinoenabled; they include properties (via the @@property, @@synthesize and
261*e4b17023SJohn Marino@@dynamic keywords), fast enumeration (not available in
262*e4b17023SJohn MarinoObjective-C++), attributes for methods (such as deprecated, noreturn,
263*e4b17023SJohn Marinosentinel, format), the unused attribute for method arguments, the
264*e4b17023SJohn Marino@@package keyword for instance variables and the @@optional and
265*e4b17023SJohn Marino@@required keywords in protocols.  You can disable all these
266*e4b17023SJohn MarinoObjective-C 2.0 language extensions with the option
267*e4b17023SJohn Marino@option{-fobjc-std=objc1}, which causes the compiler to recognize the
268*e4b17023SJohn Marinosame Objective-C language syntax recognized by GCC 4.0, and to produce
269*e4b17023SJohn Marinoan error if one of the new features is used.
270*e4b17023SJohn Marino
271*e4b17023SJohn MarinoGCC has currently no support for non-fragile instance variables.
272*e4b17023SJohn Marino
273*e4b17023SJohn MarinoThe authoritative manual on Objective-C 2.0 is available from Apple:
274*e4b17023SJohn Marino@itemize
275*e4b17023SJohn Marino@item
276*e4b17023SJohn Marino@uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/}
277*e4b17023SJohn Marino@end itemize
278*e4b17023SJohn Marino
279*e4b17023SJohn MarinoFor more information concerning the history of Objective-C that is
280*e4b17023SJohn Marinoavailable online, see @uref{http://gcc.gnu.org/readings.html}
281*e4b17023SJohn Marino
282*e4b17023SJohn Marino@section Go language
283*e4b17023SJohn Marino
284*e4b17023SJohn MarinoThe Go language continues to evolve as of this writing; see the
285*e4b17023SJohn Marino@uref{http://golang.org/@/doc/@/go_spec.html, current language
286*e4b17023SJohn Marinospecifications}.  At present there are no specific versions of Go, and
287*e4b17023SJohn Marinothere is no way to describe the language supported by GCC in terms of
288*e4b17023SJohn Marinoa specific version.  In general GCC tracks the evolving specification
289*e4b17023SJohn Marinoclosely, and any given release will support the language as of the
290*e4b17023SJohn Marinodate that the release was frozen.
291*e4b17023SJohn Marino
292*e4b17023SJohn Marino@section References for other languages
293*e4b17023SJohn Marino
294*e4b17023SJohn Marino@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
295*e4b17023SJohn MarinoGNAT Reference Manual}, for information on standard
296*e4b17023SJohn Marinoconformance and compatibility of the Ada compiler.
297*e4b17023SJohn Marino
298*e4b17023SJohn Marino@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details
299*e4b17023SJohn Marinoof standards supported by GNU Fortran.
300*e4b17023SJohn Marino
301*e4b17023SJohn Marino@xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj},
302*e4b17023SJohn Marinofor details of compatibility between @command{gcj} and the Java Platform.
303