Merge branch 'vendor/LIBARCHIVE' into HEAD
[dragonfly.git] / contrib / gcc-4.4 / gcc / doc / standards.texi
1 @c Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007, 2008 Free Software Foundation,
2 @c Inc.
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
5
6 @node Standards
7 @chapter Language Standards Supported by GCC
8
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.
12
13 @section C language
14 @cindex C standard
15 @cindex C standards
16 @cindex ANSI C standard
17 @cindex ANSI C
18 @cindex ANSI C89
19 @cindex C89
20 @cindex ANSI X3.159-1989
21 @cindex X3.159-1989
22 @cindex ISO C standard
23 @cindex ISO C
24 @cindex ISO C90
25 @cindex ISO/IEC 9899
26 @cindex ISO 9899
27 @cindex C90
28 @cindex ISO C94
29 @cindex C94
30 @cindex ISO C95
31 @cindex C95
32 @cindex ISO C99
33 @cindex C99
34 @cindex ISO C9X
35 @cindex C9X
36 @cindex Technical Corrigenda
37 @cindex TC1
38 @cindex Technical Corrigendum 1
39 @cindex TC2
40 @cindex Technical Corrigendum 2
41 @cindex TC3
42 @cindex Technical Corrigendum 3
43 @cindex AMD1
44 @cindex freestanding implementation
45 @cindex freestanding environment
46 @cindex hosted implementation
47 @cindex hosted environment
48 @findex __STDC_HOSTED__
49
50 GCC supports three versions of the C standard, although support for
51 the most recent version is not yet complete.
52
53 @opindex std
54 @opindex ansi
55 @opindex pedantic
56 @opindex pedantic-errors
57 The original ANSI C standard (X3.159-1989) was ratified in 1989 and
58 published in 1990.  This standard was ratified as an ISO standard
59 (ISO/IEC 9899:1990) later in 1990.  There were no technical
60 differences between these publications, although the sections of the
61 ANSI standard were renumbered and became clauses in the ISO standard.
62 This standard, in both its forms, is commonly known as @dfn{C89}, or
63 occasionally as @dfn{C90}, from the dates of ratification.  The ANSI
64 standard, but not the ISO standard, also came with a Rationale
65 document.  To select this standard in GCC, use one of the options
66 @option{-ansi}, @option{-std=c89} or @option{-std=iso9899:1990}; to obtain
67 all the diagnostics required by the standard, you should also specify
68 @option{-pedantic} (or @option{-pedantic-errors} if you want them to be
69 errors rather than warnings).  @xref{C Dialect Options,,Options
70 Controlling C Dialect}.
71
72 Errors in the 1990 ISO C standard were corrected in two Technical
73 Corrigenda published in 1994 and 1996.  GCC does not support the
74 uncorrected version.
75
76 An amendment to the 1990 standard was published in 1995.  This
77 amendment added digraphs and @code{__STDC_VERSION__} to the language,
78 but otherwise concerned the library.  This amendment is commonly known
79 as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
80 @dfn{C95}.  To select this standard in GCC, use the option
81 @option{-std=iso9899:199409} (with, as for other standard versions,
82 @option{-pedantic} to receive all required diagnostics).
83
84 A new edition of the ISO C standard was published in 1999 as ISO/IEC
85 9899:1999, and is commonly known as @dfn{C99}.  GCC has incomplete
86 support for this standard version; see
87 @uref{http://gcc.gnu.org/gcc-4.4/c99status.html} for details.  To select this
88 standard, use @option{-std=c99} or @option{-std=iso9899:1999}.  (While in
89 development, drafts of this standard version were referred to as
90 @dfn{C9X}.)
91
92 Errors in the 1999 ISO C standard were corrected in three Technical
93 Corrigenda published in 2001, 2004 and 2007.  GCC does not support the
94 uncorrected version.
95
96 By default, GCC provides some extensions to the C language that on
97 rare occasions conflict with the C standard.  @xref{C
98 Extensions,,Extensions to the C Language Family}.  Use of the
99 @option{-std} options listed above will disable these extensions where
100 they conflict with the C standard version selected.  You may also
101 select an extended version of the C language explicitly with
102 @option{-std=gnu89} (for C89 with GNU extensions) or @option{-std=gnu99}
103 (for C99 with GNU extensions).  The default, if no C language dialect
104 options are given, is @option{-std=gnu89}; this will change to
105 @option{-std=gnu99} in some future release when the C99 support is
106 complete.  Some features that are part of the C99 standard are
107 accepted as extensions in C89 mode.
108
109 The ISO C standard defines (in clause 4) two classes of conforming
110 implementation.  A @dfn{conforming hosted implementation} supports the
111 whole standard including all the library facilities; a @dfn{conforming
112 freestanding implementation} is only required to provide certain
113 library facilities: those in @code{<float.h>}, @code{<limits.h>},
114 @code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
115 @code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and
116 @code{<stdint.h>}.  In addition, complex types, added in C99, are not
117 required for freestanding implementations.  The standard also defines
118 two environments for programs, a @dfn{freestanding environment},
119 required of all implementations and which may not have library
120 facilities beyond those required of freestanding implementations,
121 where the handling of program startup and termination are
122 implementation-defined, and a @dfn{hosted environment}, which is not
123 required, in which all the library facilities are provided and startup
124 is through a function @code{int main (void)} or @code{int main (int,
125 char *[])}.  An OS kernel would be a freestanding environment; a
126 program using the facilities of an operating system would normally be
127 in a hosted implementation.
128
129 @opindex ffreestanding
130 GCC aims towards being usable as a conforming freestanding
131 implementation, or as the compiler for a conforming hosted
132 implementation.  By default, it will act as the compiler for a hosted
133 implementation, defining @code{__STDC_HOSTED__} as @code{1} and
134 presuming that when the names of ISO C functions are used, they have
135 the semantics defined in the standard.  To make it act as a conforming
136 freestanding implementation for a freestanding environment, use the
137 option @option{-ffreestanding}; it will then define
138 @code{__STDC_HOSTED__} to @code{0} and not make assumptions about the
139 meanings of function names from the standard library, with exceptions
140 noted below.  To build an OS kernel, you may well still need to make
141 your own arrangements for linking and startup.
142 @xref{C Dialect Options,,Options Controlling C Dialect}.
143
144 GCC does not provide the library facilities required only of hosted
145 implementations, nor yet all the facilities required by C99 of
146 freestanding implementations; to use the facilities of a hosted
147 environment, you will need to find them elsewhere (for example, in the
148 GNU C library).  @xref{Standard Libraries,,Standard Libraries}.
149
150 Most of the compiler support routines used by GCC are present in
151 @file{libgcc}, but there are a few exceptions.  GCC requires the
152 freestanding environment provide @code{memcpy}, @code{memmove},
153 @code{memset} and @code{memcmp}.
154 Finally, if @code{__builtin_trap} is used, and the target does
155 not implement the @code{trap} pattern, then GCC will emit a call
156 to @code{abort}.
157
158 For references to Technical Corrigenda, Rationale documents and
159 information concerning the history of C that is available online, see
160 @uref{http://gcc.gnu.org/readings.html}
161
162 @section C++ language
163
164 GCC supports the ISO C++ standard (1998) and contains experimental
165 support for the upcoming ISO C++ standard (200x).
166
167 The original ISO C++ standard was published as the ISO standard (ISO/IEC
168 14882:1998) and amended by a Technical Corrigenda published in 2003
169 (ISO/IEC 14882:2003). These standards are referred to as C++98 and
170 C++03, respectively. GCC implements the majority of C++98 (@code{export}
171 is a notable exception) and most of the changes in C++03.  To select
172 this standard in GCC, use one of the options @option{-ansi} or
173 @option{-std=c++98}; to obtain all the diagnostics required by the
174 standard, you should also specify @option{-pedantic} (or
175 @option{-pedantic-errors} if you want them to be errors rather than
176 warnings).
177
178 The ISO C++ committee is working on a new ISO C++ standard, dubbed
179 C++0x, that is intended to be published by 2009. C++0x contains several
180 changes to the C++ language, some of which have been implemented in an
181 experimental C++0x mode in GCC@. The C++0x mode in GCC tracks the draft
182 working paper for the C++0x standard; the latest working paper is
183 available on the ISO C++ committee's web site at
184 @uref{http://www.open-std.org/jtc1/sc22/wg21/}. For information
185 regarding the C++0x features available in the experimental C++0x mode,
186 see @uref{http://gcc.gnu.org/gcc-4.3/cxx0x_status.html}. To select this
187 standard in GCC, use the option @option{-std=c++0x}; to obtain all the
188 diagnostics required by the standard, you should also specify
189 @option{-pedantic} (or @option{-pedantic-errors} if you want them to be
190 errors rather than warnings).
191
192 By default, GCC provides some extensions to the C++ language; @xref{C++
193 Dialect Options,Options Controlling C++ Dialect}.  Use of the
194 @option{-std} option listed above will disable these extensions.  You
195 may also select an extended version of the C++ language explicitly with
196 @option{-std=gnu++98} (for C++98 with GNU extensions) or
197 @option{-std=gnu++0x} (for C++0x with GNU extensions).  The default, if
198 no C++ language dialect options are given, is @option{-std=gnu++98}.
199
200 @section Objective-C and Objective-C++ languages
201 @cindex Objective-C
202 @cindex Objective-C++
203
204 There is no formal written standard for Objective-C or Objective-C++@.  The most
205 authoritative manual is ``Object-Oriented Programming and the
206 Objective-C Language'', available at a number of web sites:
207
208 @itemize
209 @item
210 @uref{http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/}
211 is a recent (and periodically updated) version;
212 @item
213 @uref{http://www.toodarkpark.org/computers/objc/}
214 is an older example;
215 @item
216 @uref{http://www.gnustep.org}
217 and
218 @uref{http://gcc.gnu.org/readings.html}
219 have additional useful information.
220 @end itemize
221
222 @xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
223 GNAT Reference Manual}, for information on standard
224 conformance and compatibility of the Ada compiler.
225
226 @xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details
227 of standards supported by GNU Fortran.
228
229 @xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj},
230 for details of compatibility between @command{gcj} and the Java Platform.