]>
Commit | Line | Data |
---|---|---|
f1717362 | 1 | @c Copyright (C) 2000-2016 Free Software Foundation, Inc. |
38d07189 | 2 | @c This is part of the GCC manual. |
3 | @c For copying conditions, see the file gcc.texi. | |
4 | ||
5 | @node Standards | |
6 | @chapter Language Standards Supported by GCC | |
a7d782cd | 7 | |
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. | |
11 | ||
7760911e | 12 | @section C Language |
38d07189 | 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 | |
38d07189 | 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 | |
32074525 | 35 | @cindex ISO C11 |
36 | @cindex C11 | |
39012afb | 37 | @cindex ISO C1X |
38 | @cindex C1X | |
38d07189 | 39 | @cindex Technical Corrigenda |
40 | @cindex TC1 | |
41 | @cindex Technical Corrigendum 1 | |
42 | @cindex TC2 | |
43 | @cindex Technical Corrigendum 2 | |
e6c172ed | 44 | @cindex TC3 |
45 | @cindex Technical Corrigendum 3 | |
38d07189 | 46 | @cindex AMD1 |
47 | @cindex freestanding implementation | |
48 | @cindex freestanding environment | |
49 | @cindex hosted implementation | |
50 | @cindex hosted environment | |
51 | @findex __STDC_HOSTED__ | |
52 | ||
38d07189 | 53 | GCC supports three versions of the C standard, although support for |
54 | the most recent version is not yet complete. | |
55 | ||
56 | @opindex std | |
57 | @opindex ansi | |
58 | @opindex pedantic | |
59 | @opindex pedantic-errors | |
60 | The original ANSI C standard (X3.159-1989) was ratified in 1989 and | |
61 | published in 1990. This standard was ratified as an ISO standard | |
62 | (ISO/IEC 9899:1990) later in 1990. There were no technical | |
63 | differences between these publications, although the sections of the | |
64 | ANSI standard were renumbered and became clauses in the ISO standard. | |
65 | This standard, in both its forms, is commonly known as @dfn{C89}, or | |
66 | occasionally as @dfn{C90}, from the dates of ratification. The ANSI | |
67 | standard, but not the ISO standard, also came with a Rationale | |
68 | document. To select this standard in GCC, use one of the options | |
32f1f35b | 69 | @option{-ansi}, @option{-std=c90} or @option{-std=iso9899:1990}; to obtain |
38d07189 | 70 | all the diagnostics required by the standard, you should also specify |
71 | @option{-pedantic} (or @option{-pedantic-errors} if you want them to be | |
72 | errors rather than warnings). @xref{C Dialect Options,,Options | |
73 | Controlling C Dialect}. | |
74 | ||
75 | Errors in the 1990 ISO C standard were corrected in two Technical | |
76 | Corrigenda published in 1994 and 1996. GCC does not support the | |
77 | uncorrected version. | |
78 | ||
79 | An amendment to the 1990 standard was published in 1995. This | |
80 | amendment added digraphs and @code{__STDC_VERSION__} to the language, | |
81 | but otherwise concerned the library. This amendment is commonly known | |
82 | as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or | |
83 | @dfn{C95}. To select this standard in GCC, use the option | |
84 | @option{-std=iso9899:199409} (with, as for other standard versions, | |
85 | @option{-pedantic} to receive all required diagnostics). | |
86 | ||
87 | A new edition of the ISO C standard was published in 1999 as ISO/IEC | |
2ab97b45 | 88 | 9899:1999, and is commonly known as @dfn{C99}. GCC has substantially |
89 | complete support for this standard version; see | |
38d07189 | 90 | @uref{http://gcc.gnu.org/c99status.html} for details. To select this |
91 | standard, use @option{-std=c99} or @option{-std=iso9899:1999}. (While in | |
92 | development, drafts of this standard version were referred to as | |
93 | @dfn{C9X}.) | |
94 | ||
e6c172ed | 95 | Errors in the 1999 ISO C standard were corrected in three Technical |
96 | Corrigenda published in 2001, 2004 and 2007. GCC does not support the | |
97 | uncorrected version. | |
614233f7 | 98 | |
32074525 | 99 | A fourth version of the C standard, known as @dfn{C11}, was published |
2ab97b45 | 100 | in 2011 as ISO/IEC 9899:2011. GCC has substantially complete support |
101 | for this standard, enabled with @option{-std=c11} or | |
32074525 | 102 | @option{-std=iso9899:2011}. (While in development, drafts of this |
103 | standard version were referred to as @dfn{C1X}.) | |
39012afb | 104 | |
38d07189 | 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}. Use of the | |
108 | @option{-std} options listed above will disable these extensions where | |
109 | they conflict with the C standard version selected. You may also | |
110 | select an extended version of the C language explicitly with | |
39012afb | 111 | @option{-std=gnu90} (for C90 with GNU extensions), @option{-std=gnu99} |
32074525 | 112 | (for C99 with GNU extensions) or @option{-std=gnu11} (for C11 with GNU |
8c7631cc | 113 | extensions). The default, if no C language dialect options are given, |
114 | is @option{-std=gnu11}. 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. | |
38d07189 | 117 | |
118 | The ISO C standard defines (in clause 4) two classes of conforming | |
119 | implementation. A @dfn{conforming hosted implementation} supports the | |
120 | whole standard including all the library facilities; a @dfn{conforming | |
121 | freestanding implementation} is only required to provide certain | |
122 | library facilities: those in @code{<float.h>}, @code{<limits.h>}, | |
123 | @code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in | |
32074525 | 124 | @code{<iso646.h>}; since C99, also those in @code{<stdbool.h>} and |
125 | @code{<stdint.h>}; and since C11, also those in @code{<stdalign.h>} | |
126 | and @code{<stdnoreturn.h>}. In addition, complex types, added in C99, are not | |
38d07189 | 127 | required for freestanding implementations. The standard also defines |
128 | two environments for programs, a @dfn{freestanding environment}, | |
129 | required of all implementations and which may not have library | |
130 | facilities beyond those required of freestanding implementations, | |
131 | where the handling of program startup and termination are | |
132 | implementation-defined, and a @dfn{hosted environment}, which is not | |
133 | required, in which all the library facilities are provided and startup | |
134 | is through a function @code{int main (void)} or @code{int main (int, | |
135 | char *[])}. An OS kernel would be a freestanding environment; a | |
136 | program using the facilities of an operating system would normally be | |
137 | in a hosted implementation. | |
138 | ||
139 | @opindex ffreestanding | |
140 | GCC aims towards being usable as a conforming freestanding | |
141 | implementation, or as the compiler for a conforming hosted | |
142 | implementation. By default, it will act as the compiler for a hosted | |
143 | implementation, defining @code{__STDC_HOSTED__} as @code{1} and | |
144 | presuming that when the names of ISO C functions are used, they have | |
145 | the semantics defined in the standard. To make it act as a conforming | |
146 | freestanding implementation for a freestanding environment, use the | |
147 | option @option{-ffreestanding}; it will then define | |
148 | @code{__STDC_HOSTED__} to @code{0} and not make assumptions about the | |
d5fdb6fc | 149 | meanings of function names from the standard library, with exceptions |
150 | noted below. To build an OS kernel, you may well still need to make | |
151 | your own arrangements for linking and startup. | |
152 | @xref{C Dialect Options,,Options Controlling C Dialect}. | |
38d07189 | 153 | |
154 | GCC does not provide the library facilities required only of hosted | |
155 | implementations, nor yet all the facilities required by C99 of | |
2ab97b45 | 156 | freestanding implementations on all platforms; to use the facilities of a hosted |
38d07189 | 157 | environment, you will need to find them elsewhere (for example, in the |
158 | GNU C library). @xref{Standard Libraries,,Standard Libraries}. | |
159 | ||
d5fdb6fc | 160 | Most of the compiler support routines used by GCC are present in |
161 | @file{libgcc}, but there are a few exceptions. GCC requires the | |
162 | freestanding environment provide @code{memcpy}, @code{memmove}, | |
f896c932 | 163 | @code{memset} and @code{memcmp}. |
7a0ad664 | 164 | Finally, if @code{__builtin_trap} is used, and the target does |
d5fdb6fc | 165 | not implement the @code{trap} pattern, then GCC will emit a call |
166 | to @code{abort}. | |
167 | ||
38d07189 | 168 | For references to Technical Corrigenda, Rationale documents and |
169 | information concerning the history of C that is available online, see | |
170 | @uref{http://gcc.gnu.org/readings.html} | |
171 | ||
7760911e | 172 | @section C++ Language |
a7d782cd | 173 | |
8a649b7e | 174 | GCC supports the original ISO C++ standard (1998) and contains |
175 | experimental support for the second ISO C++ standard (2011). | |
a7d782cd | 176 | |
177 | The original ISO C++ standard was published as the ISO standard (ISO/IEC | |
178 | 14882:1998) and amended by a Technical Corrigenda published in 2003 | |
179 | (ISO/IEC 14882:2003). These standards are referred to as C++98 and | |
180 | C++03, respectively. GCC implements the majority of C++98 (@code{export} | |
181 | is a notable exception) and most of the changes in C++03. To select | |
8a649b7e | 182 | this standard in GCC, use one of the options @option{-ansi}, |
183 | @option{-std=c++98}, or @option{-std=c++03}; to obtain all the diagnostics | |
184 | required by the standard, you should also specify @option{-pedantic} (or | |
a7d782cd | 185 | @option{-pedantic-errors} if you want them to be errors rather than |
186 | warnings). | |
187 | ||
8a649b7e | 188 | A revised ISO C++ standard was published in 2011 as ISO/IEC |
189 | 14882:2011, and is referred to as C++11; before its publication it was | |
190 | commonly referred to as C++0x. C++11 contains several | |
191 | changes to the C++ language, most of which have been implemented in an | |
192 | experimental C++11 mode in GCC@. For information | |
193 | regarding the C++11 features available in the experimental C++11 mode, | |
12786727 | 194 | see @uref{http://gcc.gnu.org/projects/@/cxx0x.html}. To select this |
8a649b7e | 195 | standard in GCC, use the option @option{-std=c++11}; to obtain all the |
a7d782cd | 196 | diagnostics required by the standard, you should also specify |
8a649b7e | 197 | @option{-pedantic} (or @option{-pedantic-errors} if you want them to |
198 | be errors rather than warnings). | |
199 | ||
200 | More information about the C++ standards is available on the ISO C++ | |
201 | committee's web site at @uref{http://www.open-std.org/@/jtc1/@/sc22/@/wg21/}. | |
a7d782cd | 202 | |
203 | By default, GCC provides some extensions to the C++ language; @xref{C++ | |
204 | Dialect Options,Options Controlling C++ Dialect}. Use of the | |
205 | @option{-std} option listed above will disable these extensions. You | |
206 | may also select an extended version of the C++ language explicitly with | |
207 | @option{-std=gnu++98} (for C++98 with GNU extensions) or | |
8a649b7e | 208 | @option{-std=gnu++11} (for C++11 with GNU extensions). The default, if |
a7d782cd | 209 | no C++ language dialect options are given, is @option{-std=gnu++98}. |
38d07189 | 210 | |
7760911e | 211 | @section Objective-C and Objective-C++ Languages |
749e254d | 212 | @cindex Objective-C |
213 | @cindex Objective-C++ | |
214 | ||
061412ad | 215 | GCC supports ``traditional'' Objective-C (also known as ``Objective-C |
1ef143b6 | 216 | 1.0'') and contains support for the Objective-C exception and |
217 | synchronization syntax. It has also support for a number of | |
218 | ``Objective-C 2.0'' language extensions, including properties, fast | |
219 | enumeration (only for Objective-C), method attributes and the | |
220 | @@optional and @@required keywords in protocols. GCC supports | |
221 | Objective-C++ and features available in Objective-C are also available | |
222 | in Objective-C++@. | |
b724fad7 | 223 | |
061412ad | 224 | GCC by default uses the GNU Objective-C runtime library, which is part |
225 | of GCC and is not the same as the Apple/NeXT Objective-C runtime | |
226 | library used on Apple systems. There are a number of differences | |
227 | documented in this manual. The options @option{-fgnu-runtime} and | |
228 | @option{-fnext-runtime} allow you to switch between producing output | |
229 | that works with the GNU Objective-C runtime library and output that | |
230 | works with the Apple/NeXT Objective-C runtime library. | |
231 | ||
232 | There is no formal written standard for Objective-C or Objective-C++@. | |
233 | The authoritative manual on traditional Objective-C (1.0) is | |
234 | ``Object-Oriented Programming and the Objective-C Language'', | |
235 | available at a number of web sites: | |
b724fad7 | 236 | @itemize |
237 | @item | |
061412ad | 238 | @uref{http://www.gnustep.org/@/resources/@/documentation/@/ObjectivCBook.pdf} |
239 | is the original NeXTstep document; | |
b724fad7 | 240 | @item |
f05fd450 | 241 | @uref{http://objc.toodarkpark.net} |
061412ad | 242 | is the same document in another format; |
b724fad7 | 243 | @item |
061412ad | 244 | @uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/} |
245 | has an updated version but make sure you search for ``Object Oriented Programming and the Objective-C Programming Language 1.0'', | |
246 | not documentation on the newer ``Objective-C 2.0'' language | |
b724fad7 | 247 | @end itemize |
38d07189 | 248 | |
061412ad | 249 | The Objective-C exception and synchronization syntax (that is, the |
250 | keywords @@try, @@throw, @@catch, @@finally and @@synchronized) is | |
1ef143b6 | 251 | supported by GCC and is enabled with the option |
061412ad | 252 | @option{-fobjc-exceptions}. The syntax is briefly documented in this |
253 | manual and in the Objective-C 2.0 manuals from Apple. | |
254 | ||
1ef143b6 | 255 | The Objective-C 2.0 language extensions and features are automatically |
256 | enabled; they include properties (via the @@property, @@synthesize and | |
257 | @@dynamic keywords), fast enumeration (not available in | |
258 | Objective-C++), attributes for methods (such as deprecated, noreturn, | |
259 | sentinel, format), the unused attribute for method arguments, the | |
260 | @@package keyword for instance variables and the @@optional and | |
261 | @@required keywords in protocols. You can disable all these | |
262 | Objective-C 2.0 language extensions with the option | |
263 | @option{-fobjc-std=objc1}, which causes the compiler to recognize the | |
264 | same Objective-C language syntax recognized by GCC 4.0, and to produce | |
265 | an error if one of the new features is used. | |
266 | ||
267 | GCC has currently no support for non-fragile instance variables. | |
268 | ||
269 | The authoritative manual on Objective-C 2.0 is available from Apple: | |
061412ad | 270 | @itemize |
271 | @item | |
272 | @uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/} | |
273 | @end itemize | |
274 | ||
275 | For more information concerning the history of Objective-C that is | |
276 | available online, see @uref{http://gcc.gnu.org/readings.html} | |
277 | ||
7760911e | 278 | @section Go Language |
e440a328 | 279 | |
224959cb | 280 | As of the GCC 4.7.1 release, GCC supports the Go 1 language standard, |
281 | described at @uref{http://golang.org/doc/go1.html}. | |
e440a328 | 282 | |
7760911e | 283 | @section References for Other Languages |
e440a328 | 284 | |
228c5b30 | 285 | @xref{Top, GNAT Reference Manual, About This Guide, gnat_rm, |
38d07189 | 286 | GNAT Reference Manual}, for information on standard |
287 | conformance and compatibility of the Ada compiler. | |
288 | ||
0d0147a5 | 289 | @xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details |
290 | of standards supported by GNU Fortran. | |
38d07189 | 291 | |
292 | @xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj}, | |
228c76d8 | 293 | for details of compatibility between @command{gcj} and the Java Platform. |