6 Using the GNU Compiler Collection (GCC)
also those in <iso646.h>; and in C99, also those in <stdbool.h> and <stdint.h>. In ad-
dition, complex types, added in C99, are not required for freestanding implementations. The
standard also defines two environments for programs, a freestanding environment, required
of all implementations and which may not have library facilities beyond those required of
freestanding implementations, where the handling of program startup and termination are
implementation-defined, and a hosted environment, which is not required, in which all the
library facilities are provided and startup is through a function int main (void) or int
main (int, char *[]). An OS kernel would be a freestanding environment; a program
using the facilities of an operating sys tem would normally be in a hosted implementation.
GCC aims towards being usable as a conforming freestanding implementation, or as the
compiler for a conforming hosted implementation. By default, it will act as the compiler for a
hosted implementation, defining __STDC_HOSTED__ as 1 and presuming that when the names
of ISO C functions are used, they have the se mantics defined in the standard. To make it act
as a conforming freestanding implementation for a freestanding environment, use the option
‘-ffreestanding’; it will then define __STDC_HOSTED__ to 0 and not make assumptions
about the meanings of function names from the standard library, with exceptions noted
below. To build an OS kernel, you may well still need to make your own arrangements for
linking and startup. See Section 3.4 [Options Controlling C Dialect], page 28.
GCC does not provide the library facilities required only of hosted implementations, nor
yet all the facilities required by C99 of freestanding implementations; to use the facilities
of a hosted environment, you will need to find them elsewhere (for example, in the GNU C
library). See Section 11.6 [Standard Libraries], page 596.
Most of the compiler support routines used by GCC are present in ‘libgcc’, but there
are a few exceptions. GCC requires the freestanding environment provide memcpy, memmove,
memset and memcmp. Finally, if __builtin_trap is use d, and the target does not implement
the trap pattern, then GCC will e mit a call to abort.
For references to Technical Corrigenda, Rationale documents and information concerning
the history of C that is available online, se e http://gcc.gnu.org/readings.html
2.2 C++ language
GCC supports the ISO C++ standard (1998) and contains experimental support for the
upcoming ISO C++ standard (200x).
The original ISO C++ standard was published as the ISO standard (ISO/IEC 14882:1998)
and amended by a Technical Corrigenda published in 2003 (ISO/IEC 14882:2003). These
standards are referred to as C++98 and C++03, respectively. GCC implements the m ajority
of C++98 (export is a notable e xception) and most of the changes in C++03. To select this
standard in GCC, use one of the options ‘-ansi’ or ‘-std=c++98’; to obtain all the diagnos-
tics required by the standard, you should also specify ‘-pedantic’ (or ‘-pedantic-errors’
if you want them to be errors rather than warnings).
The ISO C++ committee is working on a new ISO C++ standard, dubbed C++0x,
that is intended to be published by 2009. C++0x contains several changes to the
C++ language, some of which have been implemented in an experimental C++0x
mode in GCC. The C++0x mode in GCC tracks the draft working paper for the
C++0x standard; the latest working paper is available on the ISO C++ commit-
tee’s web site at http://www.open-std.org/jtc1/sc22/wg21/. For information