1@c Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007, 2008, 2010 2@c Free Software Foundation, Inc. 3@c This is part of the GCC manual. 4@c For copying conditions, see the file gcc.texi. 5 6@node Standards 7@chapter Language Standards Supported by GCC 8 9For each language compiled by GCC for which there is a standard, GCC 10attempts to follow one or more versions of that standard, possibly 11with some exceptions, and possibly with some extensions. 12 13@section C language 14@cindex C standard 15@cindex C standards 16@cindex ANSI C standard 17@cindex ANSI C 18@cindex ANSI C89 19@cindex C89 20@cindex ANSI X3.159-1989 21@cindex X3.159-1989 22@cindex ISO C standard 23@cindex ISO C 24@cindex ISO C90 25@cindex ISO/IEC 9899 26@cindex ISO 9899 27@cindex C90 28@cindex ISO C94 29@cindex C94 30@cindex ISO C95 31@cindex C95 32@cindex ISO C99 33@cindex C99 34@cindex ISO C9X 35@cindex C9X 36@cindex ISO C11 37@cindex C11 38@cindex ISO C1X 39@cindex C1X 40@cindex Technical Corrigenda 41@cindex TC1 42@cindex Technical Corrigendum 1 43@cindex TC2 44@cindex Technical Corrigendum 2 45@cindex TC3 46@cindex Technical Corrigendum 3 47@cindex AMD1 48@cindex freestanding implementation 49@cindex freestanding environment 50@cindex hosted implementation 51@cindex hosted environment 52@findex __STDC_HOSTED__ 53 54GCC supports three versions of the C standard, although support for 55the most recent version is not yet complete. 56 57@opindex std 58@opindex ansi 59@opindex pedantic 60@opindex pedantic-errors 61The original ANSI C standard (X3.159-1989) was ratified in 1989 and 62published in 1990. This standard was ratified as an ISO standard 63(ISO/IEC 9899:1990) later in 1990. There were no technical 64differences between these publications, although the sections of the 65ANSI standard were renumbered and became clauses in the ISO standard. 66This standard, in both its forms, is commonly known as @dfn{C89}, or 67occasionally as @dfn{C90}, from the dates of ratification. The ANSI 68standard, but not the ISO standard, also came with a Rationale 69document. To select this standard in GCC, use one of the options 70@option{-ansi}, @option{-std=c90} or @option{-std=iso9899:1990}; to obtain 71all the diagnostics required by the standard, you should also specify 72@option{-pedantic} (or @option{-pedantic-errors} if you want them to be 73errors rather than warnings). @xref{C Dialect Options,,Options 74Controlling C Dialect}. 75 76Errors in the 1990 ISO C standard were corrected in two Technical 77Corrigenda published in 1994 and 1996. GCC does not support the 78uncorrected version. 79 80An amendment to the 1990 standard was published in 1995. This 81amendment added digraphs and @code{__STDC_VERSION__} to the language, 82but otherwise concerned the library. This amendment is commonly known 83as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or 84@dfn{C95}. To select this standard in GCC, use the option 85@option{-std=iso9899:199409} (with, as for other standard versions, 86@option{-pedantic} to receive all required diagnostics). 87 88A new edition of the ISO C standard was published in 1999 as ISO/IEC 899899:1999, and is commonly known as @dfn{C99}. GCC has incomplete 90support for this standard version; see 91@uref{http://gcc.gnu.org/gcc-4.7/c99status.html} for details. To select this 92standard, use @option{-std=c99} or @option{-std=iso9899:1999}. (While in 93development, drafts of this standard version were referred to as 94@dfn{C9X}.) 95 96Errors in the 1999 ISO C standard were corrected in three Technical 97Corrigenda published in 2001, 2004 and 2007. GCC does not support the 98uncorrected version. 99 100A fourth version of the C standard, known as @dfn{C11}, was published 101in 2011 as ISO/IEC 9899:2011. GCC has limited incomplete support for 102parts of this standard, enabled with @option{-std=c11} or 103@option{-std=iso9899:2011}. (While in development, drafts of this 104standard version were referred to as @dfn{C1X}.) 105 106By default, GCC provides some extensions to the C language that on 107rare occasions conflict with the C standard. @xref{C 108Extensions,,Extensions to the C Language Family}. Use of the 109@option{-std} options listed above will disable these extensions where 110they conflict with the C standard version selected. You may also 111select an extended version of the C language explicitly with 112@option{-std=gnu90} (for C90 with GNU extensions), @option{-std=gnu99} 113(for C99 with GNU extensions) or @option{-std=gnu11} (for C11 with GNU 114extensions). The default, if no C language dialect 115options are given, is @option{-std=gnu90}; this will change to 116@option{-std=gnu99} or @option{-std=gnu11} in some future release when 117the C99 or C11 support is 118complete. Some features that are part of the C99 standard are 119accepted as extensions in C90 mode, and some features that are part of 120the C11 standard are accepted as extensions in C90 and C99 modes. 121 122The ISO C standard defines (in clause 4) two classes of conforming 123implementation. A @dfn{conforming hosted implementation} supports the 124whole standard including all the library facilities; a @dfn{conforming 125freestanding implementation} is only required to provide certain 126library facilities: those in @code{<float.h>}, @code{<limits.h>}, 127@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in 128@code{<iso646.h>}; since C99, also those in @code{<stdbool.h>} and 129@code{<stdint.h>}; and since C11, also those in @code{<stdalign.h>} 130and @code{<stdnoreturn.h>}. In addition, complex types, added in C99, are not 131required for freestanding implementations. The standard also defines 132two environments for programs, a @dfn{freestanding environment}, 133required of all implementations and which may not have library 134facilities beyond those required of freestanding implementations, 135where the handling of program startup and termination are 136implementation-defined, and a @dfn{hosted environment}, which is not 137required, in which all the library facilities are provided and startup 138is through a function @code{int main (void)} or @code{int main (int, 139char *[])}. An OS kernel would be a freestanding environment; a 140program using the facilities of an operating system would normally be 141in a hosted implementation. 142 143@opindex ffreestanding 144GCC aims towards being usable as a conforming freestanding 145implementation, or as the compiler for a conforming hosted 146implementation. By default, it will act as the compiler for a hosted 147implementation, defining @code{__STDC_HOSTED__} as @code{1} and 148presuming that when the names of ISO C functions are used, they have 149the semantics defined in the standard. To make it act as a conforming 150freestanding implementation for a freestanding environment, use the 151option @option{-ffreestanding}; it will then define 152@code{__STDC_HOSTED__} to @code{0} and not make assumptions about the 153meanings of function names from the standard library, with exceptions 154noted below. To build an OS kernel, you may well still need to make 155your own arrangements for linking and startup. 156@xref{C Dialect Options,,Options Controlling C Dialect}. 157 158GCC does not provide the library facilities required only of hosted 159implementations, nor yet all the facilities required by C99 of 160freestanding implementations; to use the facilities of a hosted 161environment, you will need to find them elsewhere (for example, in the 162GNU C library). @xref{Standard Libraries,,Standard Libraries}. 163 164Most of the compiler support routines used by GCC are present in 165@file{libgcc}, but there are a few exceptions. GCC requires the 166freestanding environment provide @code{memcpy}, @code{memmove}, 167@code{memset} and @code{memcmp}. 168Finally, if @code{__builtin_trap} is used, and the target does 169not implement the @code{trap} pattern, then GCC will emit a call 170to @code{abort}. 171 172For references to Technical Corrigenda, Rationale documents and 173information concerning the history of C that is available online, see 174@uref{http://gcc.gnu.org/readings.html} 175 176@section C++ language 177 178GCC supports the original ISO C++ standard (1998) and contains 179experimental support for the second ISO C++ standard (2011). 180 181The original ISO C++ standard was published as the ISO standard (ISO/IEC 18214882:1998) and amended by a Technical Corrigenda published in 2003 183(ISO/IEC 14882:2003). These standards are referred to as C++98 and 184C++03, respectively. GCC implements the majority of C++98 (@code{export} 185is a notable exception) and most of the changes in C++03. To select 186this standard in GCC, use one of the options @option{-ansi}, 187@option{-std=c++98}, or @option{-std=c++03}; to obtain all the diagnostics 188required by the standard, you should also specify @option{-pedantic} (or 189@option{-pedantic-errors} if you want them to be errors rather than 190warnings). 191 192A revised ISO C++ standard was published in 2011 as ISO/IEC 19314882:2011, and is referred to as C++11; before its publication it was 194commonly referred to as C++0x. C++11 contains several 195changes to the C++ language, most of which have been implemented in an 196experimental C++11 mode in GCC@. For information 197regarding the C++11 features available in the experimental C++11 mode, 198see @uref{http://gcc.gnu.org/projects/@/cxx0x.html}. To select this 199standard in GCC, use the option @option{-std=c++11}; to obtain all the 200diagnostics required by the standard, you should also specify 201@option{-pedantic} (or @option{-pedantic-errors} if you want them to 202be errors rather than warnings). 203 204More information about the C++ standards is available on the ISO C++ 205committee's web site at @uref{http://www.open-std.org/@/jtc1/@/sc22/@/wg21/}. 206 207By default, GCC provides some extensions to the C++ language; @xref{C++ 208Dialect Options,Options Controlling C++ Dialect}. Use of the 209@option{-std} option listed above will disable these extensions. You 210may also select an extended version of the C++ language explicitly with 211@option{-std=gnu++98} (for C++98 with GNU extensions) or 212@option{-std=gnu++11} (for C++11 with GNU extensions). The default, if 213no C++ language dialect options are given, is @option{-std=gnu++98}. 214 215@section Objective-C and Objective-C++ languages 216@cindex Objective-C 217@cindex Objective-C++ 218 219GCC supports ``traditional'' Objective-C (also known as ``Objective-C 2201.0'') and contains support for the Objective-C exception and 221synchronization syntax. It has also support for a number of 222``Objective-C 2.0'' language extensions, including properties, fast 223enumeration (only for Objective-C), method attributes and the 224@@optional and @@required keywords in protocols. GCC supports 225Objective-C++ and features available in Objective-C are also available 226in Objective-C++@. 227 228GCC by default uses the GNU Objective-C runtime library, which is part 229of GCC and is not the same as the Apple/NeXT Objective-C runtime 230library used on Apple systems. There are a number of differences 231documented in this manual. The options @option{-fgnu-runtime} and 232@option{-fnext-runtime} allow you to switch between producing output 233that works with the GNU Objective-C runtime library and output that 234works with the Apple/NeXT Objective-C runtime library. 235 236There is no formal written standard for Objective-C or Objective-C++@. 237The authoritative manual on traditional Objective-C (1.0) is 238``Object-Oriented Programming and the Objective-C Language'', 239available at a number of web sites: 240@itemize 241@item 242@uref{http://www.gnustep.org/@/resources/@/documentation/@/ObjectivCBook.pdf} 243is the original NeXTstep document; 244@item 245@uref{http://objc.toodarkpark.net} 246is the same document in another format; 247@item 248@uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/} 249has an updated version but make sure you search for ``Object Oriented Programming and the Objective-C Programming Language 1.0'', 250not documentation on the newer ``Objective-C 2.0'' language 251@end itemize 252 253The Objective-C exception and synchronization syntax (that is, the 254keywords @@try, @@throw, @@catch, @@finally and @@synchronized) is 255supported by GCC and is enabled with the option 256@option{-fobjc-exceptions}. The syntax is briefly documented in this 257manual and in the Objective-C 2.0 manuals from Apple. 258 259The Objective-C 2.0 language extensions and features are automatically 260enabled; they include properties (via the @@property, @@synthesize and 261@@dynamic keywords), fast enumeration (not available in 262Objective-C++), attributes for methods (such as deprecated, noreturn, 263sentinel, format), the unused attribute for method arguments, the 264@@package keyword for instance variables and the @@optional and 265@@required keywords in protocols. You can disable all these 266Objective-C 2.0 language extensions with the option 267@option{-fobjc-std=objc1}, which causes the compiler to recognize the 268same Objective-C language syntax recognized by GCC 4.0, and to produce 269an error if one of the new features is used. 270 271GCC has currently no support for non-fragile instance variables. 272 273The authoritative manual on Objective-C 2.0 is available from Apple: 274@itemize 275@item 276@uref{http://developer.apple.com/@/mac/@/library/@/documentation/@/Cocoa/@/Conceptual/@/ObjectiveC/} 277@end itemize 278 279For more information concerning the history of Objective-C that is 280available online, see @uref{http://gcc.gnu.org/readings.html} 281 282@section Go language 283 284The Go language continues to evolve as of this writing; see the 285@uref{http://golang.org/@/doc/@/go_spec.html, current language 286specifications}. At present there are no specific versions of Go, and 287there is no way to describe the language supported by GCC in terms of 288a specific version. In general GCC tracks the evolving specification 289closely, and any given release will support the language as of the 290date that the release was frozen. 291 292@section References for other languages 293 294@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm, 295GNAT Reference Manual}, for information on standard 296conformance and compatibility of the Ada compiler. 297 298@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details 299of standards supported by GNU Fortran. 300 301@xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj}, 302for details of compatibility between @command{gcj} and the Java Platform. 303