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