1@c Copyright (C) 2000-2020 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 8For each language compiled by GCC for which there is a standard, GCC 9attempts to follow one or more versions of that standard, possibly 10with some exceptions, and possibly with some extensions. 11 12@section C Language 13@cindex C standard 14@cindex C standards 15@cindex ANSI C standard 16@cindex ANSI C 17@cindex ANSI C89 18@cindex C89 19@cindex ANSI X3.159-1989 20@cindex X3.159-1989 21@cindex ISO C standard 22@cindex ISO C 23@cindex ISO C90 24@cindex ISO/IEC 9899 25@cindex ISO 9899 26@cindex C90 27@cindex ISO C94 28@cindex C94 29@cindex ISO C95 30@cindex C95 31@cindex ISO C99 32@cindex C99 33@cindex ISO C9X 34@cindex C9X 35@cindex ISO C11 36@cindex C11 37@cindex ISO C1X 38@cindex C1X 39@cindex ISO C17 40@cindex C17 41@cindex ISO C2X 42@cindex C2X 43@cindex Technical Corrigenda 44@cindex TC1 45@cindex Technical Corrigendum 1 46@cindex TC2 47@cindex Technical Corrigendum 2 48@cindex TC3 49@cindex Technical Corrigendum 3 50@cindex AMD1 51@cindex freestanding implementation 52@cindex freestanding environment 53@cindex hosted implementation 54@cindex hosted environment 55@findex __STDC_HOSTED__ 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. 66The ANSI 67standard, but not the ISO standard, also came with a Rationale 68document. 69This standard, in both its forms, is commonly known as @dfn{C89}, or 70occasionally as @dfn{C90}, from the dates of ratification. 71To select this standard in GCC, use one of the options 72@option{-ansi}, @option{-std=c90} or @option{-std=iso9899:1990}; to obtain 73all the diagnostics required by the standard, you should also specify 74@option{-pedantic} (or @option{-pedantic-errors} if you want them to be 75errors rather than warnings). @xref{C Dialect Options,,Options 76Controlling C Dialect}. 77 78Errors in the 1990 ISO C standard were corrected in two Technical 79Corrigenda published in 1994 and 1996. GCC does not support the 80uncorrected version. 81 82An amendment to the 1990 standard was published in 1995. This 83amendment added digraphs and @code{__STDC_VERSION__} to the language, 84but otherwise concerned the library. This amendment is commonly known 85as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or 86@dfn{C95}. To select this standard in GCC, use the option 87@option{-std=iso9899:199409} (with, as for other standard versions, 88@option{-pedantic} to receive all required diagnostics). 89 90A new edition of the ISO C standard was published in 1999 as ISO/IEC 919899:1999, and is commonly known as @dfn{C99}. (While in 92development, drafts of this standard version were referred to as 93@dfn{C9X}.) GCC has substantially 94complete support for this standard version; see 95@uref{http://gcc.gnu.org/c99status.html} for details. To select this 96standard, use @option{-std=c99} or @option{-std=iso9899:1999}. 97 98Errors in the 1999 ISO C standard were corrected in three Technical 99Corrigenda published in 2001, 2004 and 2007. GCC does not support the 100uncorrected version. 101 102A fourth version of the C standard, known as @dfn{C11}, was published 103in 2011 as ISO/IEC 9899:2011. (While in development, drafts of this 104standard version were referred to as @dfn{C1X}.) 105GCC has substantially complete support 106for this standard, enabled with @option{-std=c11} or 107@option{-std=iso9899:2011}. A version with corrections integrated was 108prepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it is 109known as @dfn{C17} and is supported with @option{-std=c17} or 110@option{-std=iso9899:2017}; the corrections are also applied with 111@option{-std=c11}, and the only difference between the options is the 112value of @code{__STDC_VERSION__}. 113 114A further version of the C standard, known as @dfn{C2X}, is under 115development; experimental and incomplete support for this is enabled 116with @option{-std=c2x}. 117 118By default, GCC provides some extensions to the C language that, on 119rare occasions conflict with the C standard. @xref{C 120Extensions,,Extensions to the C Language Family}. 121Some features that are part of the C99 standard 122are accepted as extensions in C90 mode, and some features that are part 123of the C11 standard are accepted as extensions in C90 and C99 modes. 124Use of the 125@option{-std} options listed above disables these extensions where 126they conflict with the C standard version selected. You may also 127select an extended version of the C language explicitly with 128@option{-std=gnu90} (for C90 with GNU extensions), @option{-std=gnu99} 129(for C99 with GNU extensions) or @option{-std=gnu11} (for C11 with GNU 130extensions). 131 132The default, if no C language dialect options are given, 133is @option{-std=gnu11}. 134 135The ISO C standard defines (in clause 4) two classes of conforming 136implementation. A @dfn{conforming hosted implementation} supports the 137whole standard including all the library facilities; a @dfn{conforming 138freestanding implementation} is only required to provide certain 139library facilities: those in @code{<float.h>}, @code{<limits.h>}, 140@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in 141@code{<iso646.h>}; since C99, also those in @code{<stdbool.h>} and 142@code{<stdint.h>}; and since C11, also those in @code{<stdalign.h>} 143and @code{<stdnoreturn.h>}. In addition, complex types, added in C99, are not 144required for freestanding implementations. 145 146The standard also defines two environments for programs, a 147@dfn{freestanding environment}, required of all implementations and 148which may not have library facilities beyond those required of 149freestanding implementations, where the handling of program startup 150and termination are implementation-defined; and a @dfn{hosted 151environment}, which is not required, in which all the library 152facilities are provided and startup is through a function @code{int 153main (void)} or @code{int main (int, char *[])}. An OS kernel is an example 154of a program running in a freestanding environment; 155a program using the facilities of an 156operating system is an example of a program running in a hosted environment. 157 158@opindex ffreestanding 159GCC aims towards being usable as a conforming freestanding 160implementation, or as the compiler for a conforming hosted 161implementation. By default, it acts as the compiler for a hosted 162implementation, defining @code{__STDC_HOSTED__} as @code{1} and 163presuming that when the names of ISO C functions are used, they have 164the semantics defined in the standard. To make it act as a conforming 165freestanding implementation for a freestanding environment, use the 166option @option{-ffreestanding}; it then defines 167@code{__STDC_HOSTED__} to @code{0} and does not make assumptions about the 168meanings of function names from the standard library, with exceptions 169noted below. To build an OS kernel, you may well still need to make 170your own arrangements for linking and startup. 171@xref{C Dialect Options,,Options Controlling C Dialect}. 172 173GCC does not provide the library facilities required only of hosted 174implementations, nor yet all the facilities required by C99 of 175freestanding implementations on all platforms. 176To use the facilities of a hosted 177environment, you need to find them elsewhere (for example, in the 178GNU C library). @xref{Standard Libraries,,Standard Libraries}. 179 180Most of the compiler support routines used by GCC are present in 181@file{libgcc}, but there are a few exceptions. GCC requires the 182freestanding environment provide @code{memcpy}, @code{memmove}, 183@code{memset} and @code{memcmp}. 184Finally, if @code{__builtin_trap} is used, and the target does 185not implement the @code{trap} pattern, then GCC emits a call 186to @code{abort}. 187 188For references to Technical Corrigenda, Rationale documents and 189information concerning the history of C that is available online, see 190@uref{http://gcc.gnu.org/readings.html} 191 192@section C++ Language 193 194GCC supports the original ISO C++ standard published in 1998, 195and the 2011 and 2014 revisions. 196 197The original ISO C++ standard was published as the ISO standard (ISO/IEC 19814882:1998) and amended by a Technical Corrigenda published in 2003 199(ISO/IEC 14882:2003). These standards are referred to as C++98 and 200C++03, respectively. GCC implements the majority of C++98 (@code{export} 201is a notable exception) and most of the changes in C++03. To select 202this standard in GCC, use one of the options @option{-ansi}, 203@option{-std=c++98}, or @option{-std=c++03}; to obtain all the diagnostics 204required by the standard, you should also specify @option{-pedantic} (or 205@option{-pedantic-errors} if you want them to be errors rather than 206warnings). 207 208A revised ISO C++ standard was published in 2011 as ISO/IEC 20914882:2011, and is referred to as C++11; before its publication it was 210commonly referred to as C++0x. C++11 contains several changes to the 211C++ language, all of which have been implemented in GCC@. For details 212see @uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx11}. 213To select this standard in GCC, use the option @option{-std=c++11}. 214 215Another revised ISO C++ standard was published in 2014 as ISO/IEC 21614882:2014, and is referred to as C++14; before its publication it was 217sometimes referred to as C++1y. C++14 contains several further 218changes to the C++ language, all of which have been implemented in GCC@. 219For details see @uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx14}. 220To select this standard in GCC, use the option @option{-std=c++14}. 221 222The C++ language was further revised in 2017 and ISO/IEC 14882:2017 was 223published. This is referred to as C++17, and before publication was 224often referred to as C++1z. GCC supports all the changes in the new 225specification. For further details see 226@uref{https://gcc.gnu.org/projects/@/cxx-status.html#cxx1z}. Use the option 227@option{-std=c++17} to select this variant of C++. 228 229More information about the C++ standards is available on the ISO C++ 230committee's web site at @uref{http://www.open-std.org/@/jtc1/@/sc22/@/wg21/}. 231 232To obtain all the diagnostics required by any of the standard versions 233described above you should specify @option{-pedantic} 234or @option{-pedantic-errors}, otherwise GCC will allow some non-ISO C++ 235features as extensions. @xref{Warning Options}. 236 237By default, GCC also provides some additional extensions to the C++ language 238that on rare occasions conflict with the C++ standard. @xref{C++ 239Dialect Options,Options Controlling C++ Dialect}. Use of the 240@option{-std} options listed above disables these extensions where they 241they conflict with the C++ standard version selected. You may also 242select an extended version of the C++ language explicitly with 243@option{-std=gnu++98} (for C++98 with GNU extensions), or 244@option{-std=gnu++11} (for C++11 with GNU extensions), or 245@option{-std=gnu++14} (for C++14 with GNU extensions), or 246@option{-std=gnu++17} (for C++17 with GNU extensions). 247 248The default, if 249no C++ language dialect options are given, is @option{-std=gnu++14}. 250 251@section Objective-C and Objective-C++ Languages 252@cindex Objective-C 253@cindex Objective-C++ 254 255GCC supports ``traditional'' Objective-C (also known as ``Objective-C 2561.0'') and contains support for the Objective-C exception and 257synchronization syntax. It has also support for a number of 258``Objective-C 2.0'' language extensions, including properties, fast 259enumeration (only for Objective-C), method attributes and the 260@@optional and @@required keywords in protocols. GCC supports 261Objective-C++ and features available in Objective-C are also available 262in Objective-C++@. 263 264GCC by default uses the GNU Objective-C runtime library, which is part 265of GCC and is not the same as the Apple/NeXT Objective-C runtime 266library used on Apple systems. There are a number of differences 267documented in this manual. The options @option{-fgnu-runtime} and 268@option{-fnext-runtime} allow you to switch between producing output 269that works with the GNU Objective-C runtime library and output that 270works with the Apple/NeXT Objective-C runtime library. 271 272There is no formal written standard for Objective-C or Objective-C++@. 273The authoritative manual on traditional Objective-C (1.0) is 274``Object-Oriented Programming and the Objective-C Language'': 275@uref{http://www.gnustep.org/@/resources/@/documentation/@/ObjectivCBook.pdf} 276is the original NeXTstep document. 277 278The Objective-C exception and synchronization syntax (that is, the 279keywords @code{@@try}, @code{@@throw}, @code{@@catch}, 280@code{@@finally} and @code{@@synchronized}) is 281supported by GCC and is enabled with the option 282@option{-fobjc-exceptions}. The syntax is briefly documented in this 283manual and in the Objective-C 2.0 manuals from Apple. 284 285The Objective-C 2.0 language extensions and features are automatically 286enabled; they include properties (via the @code{@@property}, 287@code{@@synthesize} and 288@code{@@dynamic keywords}), fast enumeration (not available in 289Objective-C++), attributes for methods (such as @code{deprecated}, 290@code{noreturn}, @code{sentinel}, @code{format}), 291the @code{unused} attribute for method arguments, the 292@code{@@package} keyword for instance variables and the @code{@@optional} and 293@code{@@required} keywords in protocols. You can disable all these 294Objective-C 2.0 language extensions with the option 295@option{-fobjc-std=objc1}, which causes the compiler to recognize the 296same Objective-C language syntax recognized by GCC 4.0, and to produce 297an error if one of the new features is used. 298 299GCC has currently no support for non-fragile instance variables. 300 301The authoritative manual on Objective-C 2.0 is available from Apple: 302@itemize 303@item 304@uref{https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html} 305@end itemize 306 307For more information concerning the history of Objective-C that is 308available online, see @uref{http://gcc.gnu.org/readings.html} 309 310@section Go Language 311 312As of the GCC 4.7.1 release, GCC supports the Go 1 language standard, 313described at @uref{https://golang.org/doc/go1}. 314 315@section HSA Intermediate Language (HSAIL) 316 317GCC can compile the binary representation (BRIG) of the HSAIL text format as 318described in HSA Programmer's Reference Manual version 1.0.1. This 319capability is typically utilized to implement the HSA runtime API's HSAIL 320finalization extension for a gcc supported processor. HSA standards are 321freely available at @uref{http://www.hsafoundation.com/standards/}. 322 323@section D language 324 325GCC supports the D 2.0 programming language. The D language itself is 326currently defined by its reference implementation and supporting language 327specification, described at @uref{https://dlang.org/spec/spec.html}. 328 329@section References for Other Languages 330 331@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm, 332GNAT Reference Manual}, for information on standard 333conformance and compatibility of the Ada compiler. 334 335@xref{Standards,,Standards, gfortran, The GNU Fortran Compiler}, for details 336of standards supported by GNU Fortran. 337