1 @c Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007, 2008, 2010
2 @c Free Software Foundation, Inc.
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
7 @chapter Language Standards Supported by GCC
9 For each language compiled by GCC for which there is a standard, GCC
10 attempts to follow one or more versions of that standard, possibly
11 with some exceptions, and possibly with some extensions.
16 @cindex ANSI C standard
20 @cindex ANSI X3.159-1989
22 @cindex ISO C standard
38 @cindex Technical Corrigenda
40 @cindex Technical Corrigendum 1
42 @cindex Technical Corrigendum 2
44 @cindex Technical Corrigendum 3
46 @cindex freestanding implementation
47 @cindex freestanding environment
48 @cindex hosted implementation
49 @cindex hosted environment
50 @findex __STDC_HOSTED__
52 GCC supports three versions of the C standard, although support for
53 the most recent version is not yet complete.
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 This standard, in both its forms, is commonly known as @dfn{C89}, or
65 occasionally as @dfn{C90}, from the dates of ratification. The ANSI
66 standard, but not the ISO standard, also came with a Rationale
67 document. 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
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}. GCC has incomplete
88 support for this standard version; see
89 @uref{http://gcc.gnu.org/c99status.html} for details. To select this
90 standard, use @option{-std=c99} or @option{-std=iso9899:1999}. (While in
91 development, drafts of this standard version were referred to as
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
98 A fourth version of the C standard, known as @dfn{C1X}, is under
99 development; GCC has limited preliminary support for parts of this
100 standard, enabled with @option{-std=c1x}.
102 By default, GCC provides some extensions to the C language that on
103 rare occasions conflict with the C standard. @xref{C
104 Extensions,,Extensions to the C Language Family}. Use of the
105 @option{-std} options listed above will disable these extensions where
106 they conflict with the C standard version selected. You may also
107 select an extended version of the C language explicitly with
108 @option{-std=gnu90} (for C90 with GNU extensions), @option{-std=gnu99}
109 (for C99 with GNU extensions) or @option{-std=gnu1x} (for C1X with GNU
110 extensions). The default, if no C language dialect
111 options are given, is @option{-std=gnu90}; this will change to
112 @option{-std=gnu99} in some future release when the C99 support is
113 complete. Some features that are part of the C99 standard are
114 accepted as extensions in C90 mode.
116 The ISO C standard defines (in clause 4) two classes of conforming
117 implementation. A @dfn{conforming hosted implementation} supports the
118 whole standard including all the library facilities; a @dfn{conforming
119 freestanding implementation} is only required to provide certain
120 library facilities: those in @code{<float.h>}, @code{<limits.h>},
121 @code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
122 @code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and
123 @code{<stdint.h>}. In addition, complex types, added in C99, are not
124 required for freestanding implementations. The standard also defines
125 two environments for programs, a @dfn{freestanding environment},
126 required of all implementations and which may not have library
127 facilities beyond those required of freestanding implementations,
128 where the handling of program startup and termination are
129 implementation-defined, and a @dfn{hosted environment}, which is not
130 required, in which all the library facilities are provided and startup
131 is through a function @code{int main (void)} or @code{int main (int,
132 char *[])}. An OS kernel would be a freestanding environment; a
133 program using the facilities of an operating system would normally be
134 in a hosted implementation.
136 @opindex ffreestanding
137 GCC aims towards being usable as a conforming freestanding
138 implementation, or as the compiler for a conforming hosted
139 implementation. By default, it will act as the compiler for a hosted
140 implementation, defining @code{__STDC_HOSTED__} as @code{1} and
141 presuming that when the names of ISO C functions are used, they have
142 the semantics defined in the standard. To make it act as a conforming
143 freestanding implementation for a freestanding environment, use the
144 option @option{-ffreestanding}; it will then define
145 @code{__STDC_HOSTED__} to @code{0} and not make assumptions about the
146 meanings of function names from the standard library, with exceptions
147 noted below. To build an OS kernel, you may well still need to make
148 your own arrangements for linking and startup.
149 @xref{C Dialect Options,,Options Controlling C Dialect}.
151 GCC does not provide the library facilities required only of hosted
152 implementations, nor yet all the facilities required by C99 of
153 freestanding implementations; to use the facilities of a hosted
154 environment, you will need to find them elsewhere (for example, in the
155 GNU C library). @xref{Standard Libraries,,Standard Libraries}.
157 Most of the compiler support routines used by GCC are present in
158 @file{libgcc}, but there are a few exceptions. GCC requires the
159 freestanding environment provide @code{memcpy}, @code{memmove},
160 @code{memset} and @code{memcmp}.
161 Finally, if @code{__builtin_trap} is used, and the target does
162 not implement the @code{trap} pattern, then GCC will emit a call
165 For references to Technical Corrigenda, Rationale documents and
166 information concerning the history of C that is available online, see
167 @uref{http://gcc.gnu.org/readings.html}
169 @section C++ language
171 GCC supports the ISO C++ standard (1998) and contains experimental
172 support for the upcoming ISO C++ standard (200x).
174 The original ISO C++ standard was published as the ISO standard (ISO/IEC
175 14882:1998) and amended by a Technical Corrigenda published in 2003
176 (ISO/IEC 14882:2003). These standards are referred to as C++98 and
177 C++03, respectively. GCC implements the majority of C++98 (@code{export}
178 is a notable exception) and most of the changes in C++03. To select
179 this standard in GCC, use one of the options @option{-ansi} or
180 @option{-std=c++98}; to obtain all the diagnostics required by the
181 standard, you should also specify @option{-pedantic} (or
182 @option{-pedantic-errors} if you want them to be errors rather than
185 The ISO C++ committee is working on a new ISO C++ standard, dubbed
186 C++0x, that is intended to be published by 2009. C++0x contains several
187 changes to the C++ language, some of which have been implemented in an
188 experimental C++0x mode in GCC@. The C++0x mode in GCC tracks the draft
189 working paper for the C++0x standard; the latest working paper is
190 available on the ISO C++ committee's web site at
191 @uref{http://www.open-std.org/@/jtc1/@/sc22/@/wg21/}. For information
192 regarding the C++0x features available in the experimental C++0x mode,
193 see @uref{http://gcc.gnu.org/projects/@/cxx0x.html}. To select this
194 standard in GCC, use the option @option{-std=c++0x}; to obtain all the
195 diagnostics required by the standard, you should also specify
196 @option{-pedantic} (or @option{-pedantic-errors} if you want them to be
197 errors rather than warnings).
199 By default, GCC provides some extensions to the C++ language; @xref{C++
200 Dialect Options,Options Controlling C++ Dialect}. Use of the
201 @option{-std} option listed above will disable these extensions. You
202 may also select an extended version of the C++ language explicitly with
203 @option{-std=gnu++98} (for C++98 with GNU extensions) or
204 @option{-std=gnu++0x} (for C++0x with GNU extensions). The default, if
205 no C++ language dialect options are given, is @option{-std=gnu++98}.
207 @section Objective-C and Objective-C++ languages
209 @cindex Objective-C++
211 GCC supports ``traditional'' Objective-C (also known as ``Objective-C
212 1.0'') and contains support for the Objective-C exception and
213 synchronization syntax. It has also support for a number of
214 ``Objective-C 2.0'' language extensions, including properties, fast
215 enumeration (only for Objective-C), method attributes and the
216 @@optional and @@required keywords in protocols. GCC supports
217 Objective-C++ and features available in Objective-C are also available
220 GCC by default uses the GNU Objective-C runtime library, which is part
221 of GCC and is not the same as the Apple/NeXT Objective-C runtime
222 library used on Apple systems. There are a number of differences
223 documented in this manual. The options @option{-fgnu-runtime} and
224 @option{-fnext-runtime} allow you to switch between producing output
225 that works with the GNU Objective-C runtime library and output that
226 works with the Apple/NeXT Objective-C runtime library.
228 There is no formal written standard for Objective-C or Objective-C++@.
229 The authoritative manual on traditional Objective-C (1.0) is
230 ``Object-Oriented Programming and the Objective-C Language'',
231 available at a number of web sites:
234 @uref{http://www.gnustep.org/@/resources/@/documentation/@/ObjectivCBook.pdf}
235 is the original NeXTstep document;
237 @uref{http://objc.toodarkpark.net}
238 is the same document in another format;
240 @uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/}
241 has an updated version but make sure you search for ``Object Oriented Programming and the Objective-C Programming Language 1.0'',
242 not documentation on the newer ``Objective-C 2.0'' language
245 The Objective-C exception and synchronization syntax (that is, the
246 keywords @@try, @@throw, @@catch, @@finally and @@synchronized) is
247 supported by GCC and is enabled with the option
248 @option{-fobjc-exceptions}. The syntax is briefly documented in this
249 manual and in the Objective-C 2.0 manuals from Apple.
251 The Objective-C 2.0 language extensions and features are automatically
252 enabled; they include properties (via the @@property, @@synthesize and
253 @@dynamic keywords), fast enumeration (not available in
254 Objective-C++), attributes for methods (such as deprecated, noreturn,
255 sentinel, format), the unused attribute for method arguments, the
256 @@package keyword for instance variables and the @@optional and
257 @@required keywords in protocols. You can disable all these
258 Objective-C 2.0 language extensions with the option
259 @option{-fobjc-std=objc1}, which causes the compiler to recognize the
260 same Objective-C language syntax recognized by GCC 4.0, and to produce
261 an error if one of the new features is used.
263 GCC has currently no support for non-fragile instance variables.
265 The authoritative manual on Objective-C 2.0 is available from Apple:
268 @uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/}
271 For more information concerning the history of Objective-C that is
272 available online, see @uref{http://gcc.gnu.org/readings.html}
276 The Go language continues to evolve as of this writing; see the
277 @uref{http://golang.org/@/doc/@/go_spec.html, current language
278 specifications}. At present there are no specific versions of Go, and
279 there is no way to describe the language supported by GCC in terms of
280 a specific version. In general GCC tracks the evolving specification
281 closely, and any given release will support the language as of the
282 date that the release was frozen.
284 @section References for other languages
286 @xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
287 GNAT Reference Manual}, for information on standard
288 conformance and compatibility of the Ada compiler.
290 @xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details
291 of standards supported by GNU Fortran.
293 @xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj},
294 for details of compatibility between @command{gcj} and the Java Platform.