1@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 41For each language compiled by GCC for which there is a standard, GCC 42attempts to follow one or more versions of that standard, possibly 43with some exceptions, and possibly with some extensions. 44 45GCC supports three versions of the C standard, although support for 46the most recent version is not yet complete. 47 48@opindex std 49@opindex ansi 50@opindex pedantic 51@opindex pedantic-errors 52The original ANSI C standard (X3.159-1989) was ratified in 1989 and 53published in 1990. This standard was ratified as an ISO standard 54(ISO/IEC 9899:1990) later in 1990. There were no technical 55differences between these publications, although the sections of the 56ANSI standard were renumbered and became clauses in the ISO standard. 57This standard, in both its forms, is commonly known as @dfn{C89}, or 58occasionally as @dfn{C90}, from the dates of ratification. The ANSI 59standard, but not the ISO standard, also came with a Rationale 60document. To select this standard in GCC, use one of the options 61@option{-ansi}, @option{-std=c89} or @option{-std=iso9899:1990}; to obtain 62all the diagnostics required by the standard, you should also specify 63@option{-pedantic} (or @option{-pedantic-errors} if you want them to be 64errors rather than warnings). @xref{C Dialect Options,,Options 65Controlling C Dialect}. 66 67Errors in the 1990 ISO C standard were corrected in two Technical 68Corrigenda published in 1994 and 1996. GCC does not support the 69uncorrected version. 70 71An amendment to the 1990 standard was published in 1995. This 72amendment added digraphs and @code{__STDC_VERSION__} to the language, 73but otherwise concerned the library. This amendment is commonly known 74as @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 79A new edition of the ISO C standard was published in 1999 as ISO/IEC 809899:1999, and is commonly known as @dfn{C99}. GCC has incomplete 81support for this standard version; see 82@uref{http://gcc.gnu.org/gcc-4.2/c99status.html} for details. To select this 83standard, use @option{-std=c99} or @option{-std=iso9899:1999}. (While in 84development, drafts of this standard version were referred to as 85@dfn{C9X}.) 86 87Errors in the 1999 ISO C standard were corrected in two Technical 88Corrigenda published in 2001 and 2004. GCC does not support the uncorrected 89version. 90 91By default, GCC provides some extensions to the C language that on 92rare occasions conflict with the C standard. @xref{C 93Extensions,,Extensions to the C Language Family}. Use of the 94@option{-std} options listed above will disable these extensions where 95they conflict with the C standard version selected. You may also 96select 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 99options are given, is @option{-std=gnu89}; this will change to 100@option{-std=gnu99} in some future release when the C99 support is 101complete. Some features that are part of the C99 standard are 102accepted as extensions in C89 mode. 103 104The ISO C standard defines (in clause 4) two classes of conforming 105implementation. A @dfn{conforming hosted implementation} supports the 106whole standard including all the library facilities; a @dfn{conforming 107freestanding implementation} is only required to provide certain 108library 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 112required for freestanding implementations. The standard also defines 113two environments for programs, a @dfn{freestanding environment}, 114required of all implementations and which may not have library 115facilities beyond those required of freestanding implementations, 116where the handling of program startup and termination are 117implementation-defined, and a @dfn{hosted environment}, which is not 118required, in which all the library facilities are provided and startup 119is through a function @code{int main (void)} or @code{int main (int, 120char *[])}. An OS kernel would be a freestanding environment; a 121program using the facilities of an operating system would normally be 122in a hosted implementation. 123 124@opindex ffreestanding 125GCC aims towards being usable as a conforming freestanding 126implementation, or as the compiler for a conforming hosted 127implementation. By default, it will act as the compiler for a hosted 128implementation, defining @code{__STDC_HOSTED__} as @code{1} and 129presuming that when the names of ISO C functions are used, they have 130the semantics defined in the standard. To make it act as a conforming 131freestanding implementation for a freestanding environment, use the 132option @option{-ffreestanding}; it will then define 133@code{__STDC_HOSTED__} to @code{0} and not make assumptions about the 134meanings of function names from the standard library, with exceptions 135noted below. To build an OS kernel, you may well still need to make 136your own arrangements for linking and startup. 137@xref{C Dialect Options,,Options Controlling C Dialect}. 138 139GCC does not provide the library facilities required only of hosted 140implementations, nor yet all the facilities required by C99 of 141freestanding implementations; to use the facilities of a hosted 142environment, you will need to find them elsewhere (for example, in the 143GNU C library). @xref{Standard Libraries,,Standard Libraries}. 144 145Most of the compiler support routines used by GCC are present in 146@file{libgcc}, but there are a few exceptions. GCC requires the 147freestanding environment provide @code{memcpy}, @code{memmove}, 148@code{memset} and @code{memcmp}. 149Finally, if @code{__builtin_trap} is used, and the target does 150not implement the @code{trap} pattern, then GCC will emit a call 151to @code{abort}. 152 153For references to Technical Corrigenda, Rationale documents and 154information 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 treelang 160There is no standard for treelang, which is a sample language front end 161for GCC@. Its only purpose is as a sample for people wishing to write a 162new language for GCC@. The language is documented in 163@file{gcc/treelang/treelang.texi} which can be turned into info or 164HTML format. 165 166@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm, 167GNAT Reference Manual}, for information on standard 168conformance and compatibility of the Ada compiler. 169 170@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details 171of standards supported by GNU Fortran. 172 173@xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj}, 174for details of compatibility between @command{gcj} and the Java Platform. 175