standards.texi revision 90075
190075Sobrien@c Copyright (C) 2000, 2001 Free Software Foundation, Inc.
290075Sobrien@c This is part of the GCC manual.
390075Sobrien@c For copying conditions, see the file gcc.texi.
490075Sobrien
590075Sobrien@node Standards
690075Sobrien@chapter Language Standards Supported by GCC
790075Sobrien@cindex C standard
890075Sobrien@cindex C standards
990075Sobrien@cindex ANSI C standard
1090075Sobrien@cindex ANSI C
1190075Sobrien@cindex ANSI C89
1290075Sobrien@cindex C89
1390075Sobrien@cindex ANSI X3.159-1989
1490075Sobrien@cindex X3.159-1989
1590075Sobrien@cindex ISO C standard
1690075Sobrien@cindex ISO C
1790075Sobrien@cindex ISO C89
1890075Sobrien@cindex ISO C90
1990075Sobrien@cindex ISO/IEC 9899
2090075Sobrien@cindex ISO 9899
2190075Sobrien@cindex C90
2290075Sobrien@cindex ISO C94
2390075Sobrien@cindex C94
2490075Sobrien@cindex ISO C95
2590075Sobrien@cindex C95
2690075Sobrien@cindex ISO C99
2790075Sobrien@cindex C99
2890075Sobrien@cindex ISO C9X
2990075Sobrien@cindex C9X
3090075Sobrien@cindex Technical Corrigenda
3190075Sobrien@cindex TC1
3290075Sobrien@cindex Technical Corrigendum 1
3390075Sobrien@cindex TC2
3490075Sobrien@cindex Technical Corrigendum 2
3590075Sobrien@cindex AMD1
3690075Sobrien@cindex freestanding implementation
3790075Sobrien@cindex freestanding environment
3890075Sobrien@cindex hosted implementation
3990075Sobrien@cindex hosted environment
4090075Sobrien@findex __STDC_HOSTED__
4190075Sobrien
4290075SobrienFor each language compiled by GCC for which there is a standard, GCC
4390075Sobrienattempts to follow one or more versions of that standard, possibly
4490075Sobrienwith some exceptions, and possibly with some extensions.
4590075Sobrien
4690075SobrienGCC supports three versions of the C standard, although support for
4790075Sobrienthe most recent version is not yet complete.
4890075Sobrien
4990075Sobrien@opindex std
5090075Sobrien@opindex ansi
5190075Sobrien@opindex pedantic
5290075Sobrien@opindex pedantic-errors
5390075SobrienThe original ANSI C standard (X3.159-1989) was ratified in 1989 and
5490075Sobrienpublished in 1990.  This standard was ratified as an ISO standard
5590075Sobrien(ISO/IEC 9899:1990) later in 1990.  There were no technical
5690075Sobriendifferences between these publications, although the sections of the
5790075SobrienANSI standard were renumbered and became clauses in the ISO standard.
5890075SobrienThis standard, in both its forms, is commonly known as @dfn{C89}, or
5990075Sobrienoccasionally as @dfn{C90}, from the dates of ratification.  The ANSI
6090075Sobrienstandard, but not the ISO standard, also came with a Rationale
6190075Sobriendocument.  To select this standard in GCC, use one of the options
6290075Sobrien@option{-ansi}, @option{-std=c89} or @option{-std=iso9899:1990}; to obtain
6390075Sobrienall the diagnostics required by the standard, you should also specify
6490075Sobrien@option{-pedantic} (or @option{-pedantic-errors} if you want them to be
6590075Sobrienerrors rather than warnings).  @xref{C Dialect Options,,Options
6690075SobrienControlling C Dialect}.
6790075Sobrien
6890075SobrienErrors in the 1990 ISO C standard were corrected in two Technical
6990075SobrienCorrigenda published in 1994 and 1996.  GCC does not support the
7090075Sobrienuncorrected version.
7190075Sobrien
7290075SobrienAn amendment to the 1990 standard was published in 1995.  This
7390075Sobrienamendment added digraphs and @code{__STDC_VERSION__} to the language,
7490075Sobrienbut otherwise concerned the library.  This amendment is commonly known
7590075Sobrienas @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
7690075Sobrien@dfn{C95}.  To select this standard in GCC, use the option
7790075Sobrien@option{-std=iso9899:199409} (with, as for other standard versions,
7890075Sobrien@option{-pedantic} to receive all required diagnostics).
7990075Sobrien
8090075SobrienA new edition of the ISO C standard was published in 1999 as ISO/IEC
8190075Sobrien9899:1999, and is commonly known as @dfn{C99}.  GCC has incomplete
8290075Sobriensupport for this standard version; see
8390075Sobrien@uref{http://gcc.gnu.org/c99status.html} for details.  To select this
8490075Sobrienstandard, use @option{-std=c99} or @option{-std=iso9899:1999}.  (While in
8590075Sobriendevelopment, drafts of this standard version were referred to as
8690075Sobrien@dfn{C9X}.)
8790075Sobrien
8890075SobrienErrors in the 1999 ISO C standard were corrected in a Technical
8990075SobrienCorrigendum published in 2001.  GCC does not support the uncorrected
9090075Sobrienversion.
9190075Sobrien
9290075Sobrien@opindex traditional
9390075SobrienGCC also has some limited support for traditional (pre-ISO) C with the
9490075Sobrien@option{-traditional} option.  This support may be of use for compiling
9590075Sobriensome very old programs that have not been updated to ISO C, but should
9690075Sobriennot be used for new programs.  It will not work with some modern C
9790075Sobrienlibraries such as the GNU C library.
9890075Sobrien
9990075SobrienBy default, GCC provides some extensions to the C language that on
10090075Sobrienrare occasions conflict with the C standard.  @xref{C
10190075SobrienExtensions,,Extensions to the C Language Family}.  Use of the
10290075Sobrien@option{-std} options listed above will disable these extensions where
10390075Sobrienthey conflict with the C standard version selected.  You may also
10490075Sobrienselect an extended version of the C language explicitly with
10590075Sobrien@option{-std=gnu89} (for C89 with GNU extensions) or @option{-std=gnu99}
10690075Sobrien(for C99 with GNU extensions).  The default, if no C language dialect
10790075Sobrienoptions are given, is @option{-std=gnu89}; this will change to
10890075Sobrien@option{-std=gnu99} in some future release when the C99 support is
10990075Sobriencomplete.  Some features that are part of the C99 standard are
11090075Sobrienaccepted as extensions in C89 mode.
11190075Sobrien
11290075SobrienThe ISO C standard defines (in clause 4) two classes of conforming
11390075Sobrienimplementation.  A @dfn{conforming hosted implementation} supports the
11490075Sobrienwhole standard including all the library facilities; a @dfn{conforming
11590075Sobrienfreestanding implementation} is only required to provide certain
11690075Sobrienlibrary facilities: those in @code{<float.h>}, @code{<limits.h>},
11790075Sobrien@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
11890075Sobrien@code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and
11990075Sobrien@code{<stdint.h>}.  In addition, complex types, added in C99, are not
12090075Sobrienrequired for freestanding implementations.  The standard also defines
12190075Sobrientwo environments for programs, a @dfn{freestanding environment},
12290075Sobrienrequired of all implementations and which may not have library
12390075Sobrienfacilities beyond those required of freestanding implementations,
12490075Sobrienwhere the handling of program startup and termination are
12590075Sobrienimplementation-defined, and a @dfn{hosted environment}, which is not
12690075Sobrienrequired, in which all the library facilities are provided and startup
12790075Sobrienis through a function @code{int main (void)} or @code{int main (int,
12890075Sobrienchar *[])}.  An OS kernel would be a freestanding environment; a
12990075Sobrienprogram using the facilities of an operating system would normally be
13090075Sobrienin a hosted implementation.
13190075Sobrien
13290075Sobrien@opindex ffreestanding
13390075SobrienGCC aims towards being usable as a conforming freestanding
13490075Sobrienimplementation, or as the compiler for a conforming hosted
13590075Sobrienimplementation.  By default, it will act as the compiler for a hosted
13690075Sobrienimplementation, defining @code{__STDC_HOSTED__} as @code{1} and
13790075Sobrienpresuming that when the names of ISO C functions are used, they have
13890075Sobrienthe semantics defined in the standard.  To make it act as a conforming
13990075Sobrienfreestanding implementation for a freestanding environment, use the
14090075Sobrienoption @option{-ffreestanding}; it will then define
14190075Sobrien@code{__STDC_HOSTED__} to @code{0} and not make assumptions about the
14290075Sobrienmeanings of function names from the standard library.  To build an OS
14390075Sobrienkernel, you may well still need to make your own arrangements for
14490075Sobrienlinking and startup.  @xref{C Dialect Options,,Options Controlling C
14590075SobrienDialect}.
14690075Sobrien
14790075SobrienGCC does not provide the library facilities required only of hosted
14890075Sobrienimplementations, nor yet all the facilities required by C99 of
14990075Sobrienfreestanding implementations; to use the facilities of a hosted
15090075Sobrienenvironment, you will need to find them elsewhere (for example, in the
15190075SobrienGNU C library).  @xref{Standard Libraries,,Standard Libraries}.
15290075Sobrien
15390075SobrienFor references to Technical Corrigenda, Rationale documents and
15490075Sobrieninformation concerning the history of C that is available online, see
15590075Sobrien@uref{http://gcc.gnu.org/readings.html}
15690075Sobrien
15790075Sobrien@c FIXME: details of C++ standard.
15890075Sobrien
15990075SobrienThere is no formal written standard for Objective-C@.  The most
16090075Sobrienauthoritative manual is ``Object-Oriented Programming and the
16190075SobrienObjective-C Language'', available at a number of web sites;
16290075Sobrien@uref{http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/} has a
16390075Sobrienrecent version, while @uref{http://www.toodarkpark.org/computers/objc/}
16490075Sobrienis an older example.  @uref{http://www.gnustep.org} includes useful
16590075Sobrieninformation as well.
16690075Sobrien
16790075Sobrien@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm, 
16890075SobrienGNAT Reference Manual}, for information on standard
16990075Sobrienconformance and compatibility of the Ada compiler.
17090075Sobrien
17190075Sobrien@xref{References,,Language Definition References, chill, GNU Chill},
17290075Sobrienfor details of the CHILL standard.
17390075Sobrien
17490075Sobrien@xref{Language,,The GNU Fortran Language, g77, Using and Porting GNU
17590075SobrienFortran}, for details of the Fortran language supported by GCC@.
17690075Sobrien
17790075Sobrien@xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj},
17890075Sobrienfor details of compatibility between @code{gcj} and the Java Platform.
179