1132718Skan@c Copyright (C) 2000, 2001, 2002, 2004 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 C90 1890075Sobrien@cindex ISO/IEC 9899 1990075Sobrien@cindex ISO 9899 2090075Sobrien@cindex C90 2190075Sobrien@cindex ISO C94 2290075Sobrien@cindex C94 2390075Sobrien@cindex ISO C95 2490075Sobrien@cindex C95 2590075Sobrien@cindex ISO C99 2690075Sobrien@cindex C99 2790075Sobrien@cindex ISO C9X 2890075Sobrien@cindex C9X 2990075Sobrien@cindex Technical Corrigenda 3090075Sobrien@cindex TC1 3190075Sobrien@cindex Technical Corrigendum 1 3290075Sobrien@cindex TC2 3390075Sobrien@cindex Technical Corrigendum 2 3490075Sobrien@cindex AMD1 3590075Sobrien@cindex freestanding implementation 3690075Sobrien@cindex freestanding environment 3790075Sobrien@cindex hosted implementation 3890075Sobrien@cindex hosted environment 3990075Sobrien@findex __STDC_HOSTED__ 4090075Sobrien 4190075SobrienFor each language compiled by GCC for which there is a standard, GCC 4290075Sobrienattempts to follow one or more versions of that standard, possibly 4390075Sobrienwith some exceptions, and possibly with some extensions. 4490075Sobrien 4590075SobrienGCC supports three versions of the C standard, although support for 4690075Sobrienthe most recent version is not yet complete. 4790075Sobrien 4890075Sobrien@opindex std 4990075Sobrien@opindex ansi 5090075Sobrien@opindex pedantic 5190075Sobrien@opindex pedantic-errors 5290075SobrienThe original ANSI C standard (X3.159-1989) was ratified in 1989 and 5390075Sobrienpublished in 1990. This standard was ratified as an ISO standard 5490075Sobrien(ISO/IEC 9899:1990) later in 1990. There were no technical 5590075Sobriendifferences between these publications, although the sections of the 5690075SobrienANSI standard were renumbered and became clauses in the ISO standard. 5790075SobrienThis standard, in both its forms, is commonly known as @dfn{C89}, or 5890075Sobrienoccasionally as @dfn{C90}, from the dates of ratification. The ANSI 5990075Sobrienstandard, but not the ISO standard, also came with a Rationale 6090075Sobriendocument. To select this standard in GCC, use one of the options 6190075Sobrien@option{-ansi}, @option{-std=c89} or @option{-std=iso9899:1990}; to obtain 6290075Sobrienall the diagnostics required by the standard, you should also specify 6390075Sobrien@option{-pedantic} (or @option{-pedantic-errors} if you want them to be 6490075Sobrienerrors rather than warnings). @xref{C Dialect Options,,Options 6590075SobrienControlling C Dialect}. 6690075Sobrien 6790075SobrienErrors in the 1990 ISO C standard were corrected in two Technical 6890075SobrienCorrigenda published in 1994 and 1996. GCC does not support the 6990075Sobrienuncorrected version. 7090075Sobrien 7190075SobrienAn amendment to the 1990 standard was published in 1995. This 7290075Sobrienamendment added digraphs and @code{__STDC_VERSION__} to the language, 7390075Sobrienbut otherwise concerned the library. This amendment is commonly known 7490075Sobrienas @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or 7590075Sobrien@dfn{C95}. To select this standard in GCC, use the option 7690075Sobrien@option{-std=iso9899:199409} (with, as for other standard versions, 7790075Sobrien@option{-pedantic} to receive all required diagnostics). 7890075Sobrien 7990075SobrienA new edition of the ISO C standard was published in 1999 as ISO/IEC 8090075Sobrien9899:1999, and is commonly known as @dfn{C99}. GCC has incomplete 8190075Sobriensupport for this standard version; see 82169689Skan@uref{http://gcc.gnu.org/gcc-4.2/c99status.html} for details. To select this 8390075Sobrienstandard, use @option{-std=c99} or @option{-std=iso9899:1999}. (While in 8490075Sobriendevelopment, drafts of this standard version were referred to as 8590075Sobrien@dfn{C9X}.) 8690075Sobrien 87169689SkanErrors in the 1999 ISO C standard were corrected in two Technical 88169689SkanCorrigenda published in 2001 and 2004. GCC does not support the uncorrected 8990075Sobrienversion. 9090075Sobrien 9190075SobrienBy default, GCC provides some extensions to the C language that on 9290075Sobrienrare occasions conflict with the C standard. @xref{C 9390075SobrienExtensions,,Extensions to the C Language Family}. Use of the 9490075Sobrien@option{-std} options listed above will disable these extensions where 9590075Sobrienthey conflict with the C standard version selected. You may also 9690075Sobrienselect an extended version of the C language explicitly with 9790075Sobrien@option{-std=gnu89} (for C89 with GNU extensions) or @option{-std=gnu99} 9890075Sobrien(for C99 with GNU extensions). The default, if no C language dialect 9990075Sobrienoptions are given, is @option{-std=gnu89}; this will change to 10090075Sobrien@option{-std=gnu99} in some future release when the C99 support is 10190075Sobriencomplete. Some features that are part of the C99 standard are 10290075Sobrienaccepted as extensions in C89 mode. 10390075Sobrien 10490075SobrienThe ISO C standard defines (in clause 4) two classes of conforming 10590075Sobrienimplementation. A @dfn{conforming hosted implementation} supports the 10690075Sobrienwhole standard including all the library facilities; a @dfn{conforming 10790075Sobrienfreestanding implementation} is only required to provide certain 10890075Sobrienlibrary facilities: those in @code{<float.h>}, @code{<limits.h>}, 10990075Sobrien@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in 11090075Sobrien@code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and 11190075Sobrien@code{<stdint.h>}. In addition, complex types, added in C99, are not 11290075Sobrienrequired for freestanding implementations. The standard also defines 11390075Sobrientwo environments for programs, a @dfn{freestanding environment}, 11490075Sobrienrequired of all implementations and which may not have library 11590075Sobrienfacilities beyond those required of freestanding implementations, 11690075Sobrienwhere the handling of program startup and termination are 11790075Sobrienimplementation-defined, and a @dfn{hosted environment}, which is not 11890075Sobrienrequired, in which all the library facilities are provided and startup 11990075Sobrienis through a function @code{int main (void)} or @code{int main (int, 12090075Sobrienchar *[])}. An OS kernel would be a freestanding environment; a 12190075Sobrienprogram using the facilities of an operating system would normally be 12290075Sobrienin a hosted implementation. 12390075Sobrien 12490075Sobrien@opindex ffreestanding 12590075SobrienGCC aims towards being usable as a conforming freestanding 12690075Sobrienimplementation, or as the compiler for a conforming hosted 12790075Sobrienimplementation. By default, it will act as the compiler for a hosted 12890075Sobrienimplementation, defining @code{__STDC_HOSTED__} as @code{1} and 12990075Sobrienpresuming that when the names of ISO C functions are used, they have 13090075Sobrienthe semantics defined in the standard. To make it act as a conforming 13190075Sobrienfreestanding implementation for a freestanding environment, use the 13290075Sobrienoption @option{-ffreestanding}; it will then define 13390075Sobrien@code{__STDC_HOSTED__} to @code{0} and not make assumptions about the 13496263Sobrienmeanings of function names from the standard library, with exceptions 13596263Sobriennoted below. To build an OS kernel, you may well still need to make 13696263Sobrienyour own arrangements for linking and startup. 13796263Sobrien@xref{C Dialect Options,,Options Controlling C Dialect}. 13890075Sobrien 13990075SobrienGCC does not provide the library facilities required only of hosted 14090075Sobrienimplementations, nor yet all the facilities required by C99 of 14190075Sobrienfreestanding implementations; to use the facilities of a hosted 14290075Sobrienenvironment, you will need to find them elsewhere (for example, in the 14390075SobrienGNU C library). @xref{Standard Libraries,,Standard Libraries}. 14490075Sobrien 14596263SobrienMost of the compiler support routines used by GCC are present in 14696263Sobrien@file{libgcc}, but there are a few exceptions. GCC requires the 14796263Sobrienfreestanding environment provide @code{memcpy}, @code{memmove}, 148169689Skan@code{memset} and @code{memcmp}. 149132718SkanFinally, if @code{__builtin_trap} is used, and the target does 15096263Sobriennot implement the @code{trap} pattern, then GCC will emit a call 15196263Sobriento @code{abort}. 15296263Sobrien 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 159117395Skan@cindex treelang 160117395SkanThere is no standard for treelang, which is a sample language front end 161169689Skanfor GCC@. Its only purpose is as a sample for people wishing to write a 162169689Skannew language for GCC@. The language is documented in 163117395Skan@file{gcc/treelang/treelang.texi} which can be turned into info or 164117395SkanHTML format. 165117395Skan 16696263Sobrien@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm, 16790075SobrienGNAT Reference Manual}, for information on standard 16890075Sobrienconformance and compatibility of the Ada compiler. 16990075Sobrien 170169689Skan@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details 171169689Skanof standards supported by GNU Fortran. 17290075Sobrien 17390075Sobrien@xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj}, 174117395Skanfor details of compatibility between @command{gcj} and the Java Platform. 175