OSDN Git Service

2002-06-15 Aldy Hernandez <aldyh@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / doc / standards.texi
1 @c Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
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
7 @cindex C standard
8 @cindex C standards
9 @cindex ANSI C standard
10 @cindex ANSI C
11 @cindex ANSI C89
12 @cindex C89
13 @cindex ANSI X3.159-1989
14 @cindex X3.159-1989
15 @cindex ISO C standard
16 @cindex ISO C
17 @cindex ISO C89
18 @cindex ISO C90
19 @cindex ISO/IEC 9899
20 @cindex ISO 9899
21 @cindex C90
22 @cindex ISO C94
23 @cindex C94
24 @cindex ISO C95
25 @cindex C95
26 @cindex ISO C99
27 @cindex C99
28 @cindex ISO C9X
29 @cindex C9X
30 @cindex Technical Corrigenda
31 @cindex TC1
32 @cindex Technical Corrigendum 1
33 @cindex TC2
34 @cindex Technical Corrigendum 2
35 @cindex AMD1
36 @cindex freestanding implementation
37 @cindex freestanding environment
38 @cindex hosted implementation
39 @cindex hosted environment
40 @findex __STDC_HOSTED__
41
42 For each language compiled by GCC for which there is a standard, GCC
43 attempts to follow one or more versions of that standard, possibly
44 with some exceptions, and possibly with some extensions.
45
46 GCC supports three versions of the C standard, although support for
47 the most recent version is not yet complete.
48
49 @opindex std
50 @opindex ansi
51 @opindex pedantic
52 @opindex pedantic-errors
53 The original ANSI C standard (X3.159-1989) was ratified in 1989 and
54 published in 1990.  This standard was ratified as an ISO standard
55 (ISO/IEC 9899:1990) later in 1990.  There were no technical
56 differences between these publications, although the sections of the
57 ANSI standard were renumbered and became clauses in the ISO standard.
58 This standard, in both its forms, is commonly known as @dfn{C89}, or
59 occasionally as @dfn{C90}, from the dates of ratification.  The ANSI
60 standard, but not the ISO standard, also came with a Rationale
61 document.  To select this standard in GCC, use one of the options
62 @option{-ansi}, @option{-std=c89} or @option{-std=iso9899:1990}; to obtain
63 all the diagnostics required by the standard, you should also specify
64 @option{-pedantic} (or @option{-pedantic-errors} if you want them to be
65 errors rather than warnings).  @xref{C Dialect Options,,Options
66 Controlling C Dialect}.
67
68 Errors in the 1990 ISO C standard were corrected in two Technical
69 Corrigenda published in 1994 and 1996.  GCC does not support the
70 uncorrected version.
71
72 An amendment to the 1990 standard was published in 1995.  This
73 amendment added digraphs and @code{__STDC_VERSION__} to the language,
74 but otherwise concerned the library.  This amendment is commonly known
75 as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
76 @dfn{C95}.  To select this standard in GCC, use the option
77 @option{-std=iso9899:199409} (with, as for other standard versions,
78 @option{-pedantic} to receive all required diagnostics).
79
80 A new edition of the ISO C standard was published in 1999 as ISO/IEC
81 9899:1999, and is commonly known as @dfn{C99}.  GCC has incomplete
82 support for this standard version; see
83 @uref{http://gcc.gnu.org/c99status.html} for details.  To select this
84 standard, use @option{-std=c99} or @option{-std=iso9899:1999}.  (While in
85 development, drafts of this standard version were referred to as
86 @dfn{C9X}.)
87
88 Errors in the 1999 ISO C standard were corrected in a Technical
89 Corrigendum published in 2001.  GCC does not support the uncorrected
90 version.
91
92 By default, GCC provides some extensions to the C language that on
93 rare occasions conflict with the C standard.  @xref{C
94 Extensions,,Extensions to the C Language Family}.  Use of the
95 @option{-std} options listed above will disable these extensions where
96 they conflict with the C standard version selected.  You may also
97 select an extended version of the C language explicitly with
98 @option{-std=gnu89} (for C89 with GNU extensions) or @option{-std=gnu99}
99 (for C99 with GNU extensions).  The default, if no C language dialect
100 options are given, is @option{-std=gnu89}; this will change to
101 @option{-std=gnu99} in some future release when the C99 support is
102 complete.  Some features that are part of the C99 standard are
103 accepted as extensions in C89 mode.
104
105 The ISO C standard defines (in clause 4) two classes of conforming
106 implementation.  A @dfn{conforming hosted implementation} supports the
107 whole standard including all the library facilities; a @dfn{conforming
108 freestanding implementation} is only required to provide certain
109 library facilities: those in @code{<float.h>}, @code{<limits.h>},
110 @code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
111 @code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and
112 @code{<stdint.h>}.  In addition, complex types, added in C99, are not
113 required for freestanding implementations.  The standard also defines
114 two environments for programs, a @dfn{freestanding environment},
115 required of all implementations and which may not have library
116 facilities beyond those required of freestanding implementations,
117 where the handling of program startup and termination are
118 implementation-defined, and a @dfn{hosted environment}, which is not
119 required, in which all the library facilities are provided and startup
120 is through a function @code{int main (void)} or @code{int main (int,
121 char *[])}.  An OS kernel would be a freestanding environment; a
122 program using the facilities of an operating system would normally be
123 in a hosted implementation.
124
125 @opindex ffreestanding
126 GCC aims towards being usable as a conforming freestanding
127 implementation, or as the compiler for a conforming hosted
128 implementation.  By default, it will act as the compiler for a hosted
129 implementation, defining @code{__STDC_HOSTED__} as @code{1} and
130 presuming that when the names of ISO C functions are used, they have
131 the semantics defined in the standard.  To make it act as a conforming
132 freestanding implementation for a freestanding environment, use the
133 option @option{-ffreestanding}; it will then define
134 @code{__STDC_HOSTED__} to @code{0} and not make assumptions about the
135 meanings of function names from the standard library, with exceptions
136 noted below.  To build an OS kernel, you may well still need to make
137 your own arrangements for linking and startup.
138 @xref{C Dialect Options,,Options Controlling C Dialect}.
139
140 GCC does not provide the library facilities required only of hosted
141 implementations, nor yet all the facilities required by C99 of
142 freestanding implementations; to use the facilities of a hosted
143 environment, you will need to find them elsewhere (for example, in the
144 GNU C library).  @xref{Standard Libraries,,Standard Libraries}.
145
146 Most of the compiler support routines used by GCC are present in
147 @file{libgcc}, but there are a few exceptions.  GCC requires the
148 freestanding environment provide @code{memcpy}, @code{memmove},
149 @code{memset} and @code{memcmp}.  Some older ports of GCC are 
150 configured to use the BSD @code{bcopy}, @code{bzero} and @code{bcmp}
151 functions instead, but this is deprecated for new ports.
152 Finally, if @code{__builtin_trap} is used, and the target does 
153 not implement the @code{trap} pattern, then GCC will emit a call
154 to @code{abort}.
155
156 For references to Technical Corrigenda, Rationale documents and
157 information concerning the history of C that is available online, see
158 @uref{http://gcc.gnu.org/readings.html}
159
160 @c FIXME: details of C++ standard.
161
162 There is no formal written standard for Objective-C@.  The most
163 authoritative manual is ``Object-Oriented Programming and the
164 Objective-C Language'', available at a number of web sites;
165 @uref{http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/} has a
166 recent version, while @uref{http://www.toodarkpark.org/computers/objc/}
167 is an older example.  @uref{http://www.gnustep.org} includes useful
168 information as well.
169
170 @cindex treelang
171 There is no standard for treelang, which is a sample language front end
172 for GCC. Its only purpose is as a sample for people wishing to write a
173 new language for GCC. The language is documented in
174 @file{gcc/treelang/treelang.texi} which can be turned into info or
175 HTML format.
176
177 @xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
178 GNAT Reference Manual}, for information on standard
179 conformance and compatibility of the Ada compiler.
180
181 @xref{Language,,The GNU Fortran Language, g77, Using and Porting GNU
182 Fortran}, for details of the Fortran language supported by GCC@.
183
184 @xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj},
185 for details of compatibility between @code{gcj} and the Java Platform.