📄 standards.texi
字号:
@c Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007 Free Software Foundation,@c Inc.@c This is part of the GCC manual.@c For copying conditions, see the file gcc.texi.@node Standards@chapter Language Standards Supported by GCCFor each language compiled by GCC for which there is a standard, GCCattempts to follow one or more versions of that standard, possiblywith some exceptions, and possibly with some extensions.@section C language@cindex C standard@cindex C standards@cindex ANSI C standard@cindex ANSI C@cindex ANSI C89@cindex C89@cindex ANSI X3.159-1989@cindex X3.159-1989@cindex ISO C standard@cindex ISO C@cindex ISO C90@cindex ISO/IEC 9899@cindex ISO 9899@cindex C90@cindex ISO C94@cindex C94@cindex ISO C95@cindex C95@cindex ISO C99@cindex C99@cindex ISO C9X@cindex C9X@cindex Technical Corrigenda@cindex TC1@cindex Technical Corrigendum 1@cindex TC2@cindex Technical Corrigendum 2@cindex TC3@cindex Technical Corrigendum 3@cindex AMD1@cindex freestanding implementation@cindex freestanding environment@cindex hosted implementation@cindex hosted environment@findex __STDC_HOSTED__GCC supports three versions of the C standard, although support forthe most recent version is not yet complete.@opindex std@opindex ansi@opindex pedantic@opindex pedantic-errorsThe original ANSI C standard (X3.159-1989) was ratified in 1989 andpublished in 1990. This standard was ratified as an ISO standard(ISO/IEC 9899:1990) later in 1990. There were no technicaldifferences between these publications, although the sections of theANSI standard were renumbered and became clauses in the ISO standard.This standard, in both its forms, is commonly known as @dfn{C89}, oroccasionally as @dfn{C90}, from the dates of ratification. The ANSIstandard, but not the ISO standard, also came with a Rationaledocument. To select this standard in GCC, use one of the options@option{-ansi}, @option{-std=c89} or @option{-std=iso9899:1990}; to obtainall the diagnostics required by the standard, you should also specify@option{-pedantic} (or @option{-pedantic-errors} if you want them to beerrors rather than warnings). @xref{C Dialect Options,,OptionsControlling C Dialect}.Errors in the 1990 ISO C standard were corrected in two TechnicalCorrigenda published in 1994 and 1996. GCC does not support theuncorrected version.An amendment to the 1990 standard was published in 1995. Thisamendment added digraphs and @code{__STDC_VERSION__} to the language,but otherwise concerned the library. This amendment is commonly knownas @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or@dfn{C95}. To select this standard in GCC, use the option@option{-std=iso9899:199409} (with, as for other standard versions,@option{-pedantic} to receive all required diagnostics).A new edition of the ISO C standard was published in 1999 as ISO/IEC9899:1999, and is commonly known as @dfn{C99}. GCC has incompletesupport for this standard version; see@uref{http://gcc.gnu.org/gcc-4.3/c99status.html} for details. To select thisstandard, use @option{-std=c99} or @option{-std=iso9899:1999}. (While indevelopment, drafts of this standard version were referred to as@dfn{C9X}.)Errors in the 1999 ISO C standard were corrected in three TechnicalCorrigenda published in 2001, 2004 and 2007. GCC does not support theuncorrected version.By default, GCC provides some extensions to the C language that onrare occasions conflict with the C standard. @xref{CExtensions,,Extensions to the C Language Family}. Use of the@option{-std} options listed above will disable these extensions wherethey conflict with the C standard version selected. You may alsoselect an extended version of the C language explicitly with@option{-std=gnu89} (for C89 with GNU extensions) or @option{-std=gnu99}(for C99 with GNU extensions). The default, if no C language dialectoptions are given, is @option{-std=gnu89}; this will change to@option{-std=gnu99} in some future release when the C99 support iscomplete. Some features that are part of the C99 standard areaccepted as extensions in C89 mode.The ISO C standard defines (in clause 4) two classes of conformingimplementation. A @dfn{conforming hosted implementation} supports thewhole standard including all the library facilities; a @dfn{conformingfreestanding implementation} is only required to provide certainlibrary facilities: those in @code{<float.h>}, @code{<limits.h>},@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in@code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and@code{<stdint.h>}. In addition, complex types, added in C99, are notrequired for freestanding implementations. The standard also definestwo environments for programs, a @dfn{freestanding environment},required of all implementations and which may not have libraryfacilities beyond those required of freestanding implementations,where the handling of program startup and termination areimplementation-defined, and a @dfn{hosted environment}, which is notrequired, in which all the library facilities are provided and startupis through a function @code{int main (void)} or @code{int main (int,char *[])}. An OS kernel would be a freestanding environment; aprogram using the facilities of an operating system would normally bein a hosted implementation.@opindex ffreestandingGCC aims towards being usable as a conforming freestandingimplementation, or as the compiler for a conforming hostedimplementation. By default, it will act as the compiler for a hostedimplementation, defining @code{__STDC_HOSTED__} as @code{1} andpresuming that when the names of ISO C functions are used, they havethe semantics defined in the standard. To make it act as a conformingfreestanding implementation for a freestanding environment, use theoption @option{-ffreestanding}; it will then define@code{__STDC_HOSTED__} to @code{0} and not make assumptions about themeanings of function names from the standard library, with exceptionsnoted below. To build an OS kernel, you may well still need to makeyour own arrangements for linking and startup.@xref{C Dialect Options,,Options Controlling C Dialect}.GCC does not provide the library facilities required only of hostedimplementations, nor yet all the facilities required by C99 offreestanding implementations; to use the facilities of a hostedenvironment, you will need to find them elsewhere (for example, in theGNU C library). @xref{Standard Libraries,,Standard Libraries}.Most of the compiler support routines used by GCC are present in@file{libgcc}, but there are a few exceptions. GCC requires thefreestanding environment provide @code{memcpy}, @code{memmove},@code{memset} and @code{memcmp}.Finally, if @code{__builtin_trap} is used, and the target doesnot implement the @code{trap} pattern, then GCC will emit a callto @code{abort}.For references to Technical Corrigenda, Rationale documents andinformation concerning the history of C that is available online, see@uref{http://gcc.gnu.org/readings.html}@section C++ languageGCC supports the ISO C++ standard (1998) and contains experimentalsupport for the upcoming ISO C++ standard (200x).The original ISO C++ standard was published as the ISO standard (ISO/IEC14882:1998) and amended by a Technical Corrigenda published in 2003(ISO/IEC 14882:2003). These standards are referred to as C++98 andC++03, respectively. GCC implements the majority of C++98 (@code{export}is a notable exception) and most of the changes in C++03. To selectthis standard in GCC, use one of the options @option{-ansi} or@option{-std=c++98}; to obtain all the diagnostics required by thestandard, you should also specify @option{-pedantic} (or@option{-pedantic-errors} if you want them to be errors rather thanwarnings).The ISO C++ committee is working on a new ISO C++ standard, dubbedC++0x, that is intended to be published by 2009. C++0x contains severalchanges to the C++ language, some of which have been implemented in anexperimental C++0x mode in GCC@. The C++0x mode in GCC tracks the draftworking paper for the C++0x standard; the latest working paper isavailable on the ISO C++ committee's web site at@uref{http://www.open-std.org/jtc1/sc22/wg21/}. For informationregarding the C++0x features available in the experimental C++0x mode,see @uref{http://gcc.gnu.org/gcc-4.3/cxx0x_status.html}. To select thisstandard in GCC, use the option @option{-std=c++0x}; to obtain all thediagnostics required by the standard, you should also specify@option{-pedantic} (or @option{-pedantic-errors} if you want them to beerrors rather than warnings).By default, GCC provides some extensions to the C++ language; @xref{C++Dialect Options,Options Controlling C++ Dialect}. Use of the@option{-std} option listed above will disable these extensions. Youmay also select an extended version of the C++ language explicitly with@option{-std=gnu++98} (for C++98 with GNU extensions) or@option{-std=gnu++0x} (for C++0x with GNU extensions). The default, ifno C++ language dialect options are given, is @option{-std=gnu++98}.@section Objective-C and Objective-C++ languages@cindex Objective-C@cindex Objective-C++There is no formal written standard for Objective-C or Objective-C++@. The mostauthoritative manual is ``Object-Oriented Programming and theObjective-C Language'', available at a number of web sites:@itemize@item@uref{http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/}is a recent (and periodically updated) version;@item@uref{http://www.toodarkpark.org/computers/objc/}is an older example;@item@uref{http://www.gnustep.org}and@uref{http://gcc.gnu.org/readings.html}have additional useful information.@end itemize@section Treelang language@cindex treelangThere is no standard for treelang, which is a sample language front endfor GCC@. Its only purpose is as a sample for people wishing to write anew language for GCC@. The language is documented in@file{gcc/treelang/treelang.texi} which can be turned into info orHTML format.@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,GNAT Reference Manual}, for information on standardconformance and compatibility of the Ada compiler.@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for detailsof standards supported by GNU Fortran.@xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj},for details of compatibility between @command{gcj} and the Java Platform.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -