Next:GCC Command Options, Previous:Programming Languages Supported by GCC, Up:Introduction [Contents][Index]
For 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.
The 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.The ANSIstandard, but not the ISO standard, also came with a Rationaledocument. This standard, in both its forms, is commonly known asC89, oroccasionally asC90, from the dates of ratification.To select this standard in GCC, use one of the options-ansi,-std=c90 or-std=iso9899:1990; to obtainall the diagnostics required by the standard, you should also specify-pedantic (or-pedantic-errors if you want them to beerrors rather than warnings). SeeOptionsControlling 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__STDC_VERSION__ to the language,but otherwise concerned the library. This amendment is commonly knownasAMD1; the amended standard is sometimes known asC94 orC95. To select this standard in GCC, use the option-std=iso9899:199409 (with, as for other standard versions,-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 asC99. (While indevelopment, drafts of this standard version were referred to asC9X.) GCC has substantiallycomplete support for this standard version; seehttps://gcc.gnu.org/projects/c-status.html for details. To selectthis standard, use-std=c99 or-std=iso9899:1999.
Errors in the 1999 ISO C standard were corrected in three TechnicalCorrigenda published in 2001, 2004 and 2007. GCC does not support theuncorrected version.
A fourth version of the C standard, known asC11, was publishedin 2011 as ISO/IEC 9899:2011. (While in development, drafts of thisstandard version were referred to asC1X.)GCC has substantially complete supportfor this standard, enabled with-std=c11 or-std=iso9899:2011. A version with corrections integrated wasprepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it isknown asC17 and is supported with-std=c17 or-std=iso9899:2017; the corrections are also applied with-std=c11, and the only difference between the options is thevalue of__STDC_VERSION__.
A fifth version of the C standard, known asC23, was publishedin 2024 as ISO/IEC 9899:2024.(While in development, drafts of this standard version were referredto asC2X.) Support for this isenabled with-std=c23 or-std=iso9899:2024.
A further version of the C standard, known asC2Y, is underdevelopment; experimental and incomplete support for this is enabledwith-std=c2y.
By default, GCC provides some extensions to the C language that, onrare occasions conflict with the C standard. SeeExtensions to the C Language Family. Some features that are part of the C99 standardare accepted as extensions in C90 mode, and some features that are partof the C11 standard are accepted as extensions in C90 and C99 modes.Use of the-std options listed above disables these extensions wherethey conflict with the C standard version selected. You may alsoselect an extended version of the C language explicitly with-std=gnu90 (for C90 with GNU extensions),-std=gnu99(for C99 with GNU extensions),-std=gnu11 (for C11 with GNUextensions),-std=gnu17 (for C17 with GNU extensions) or-std=gnu23 (for C23 with GNU extensions).
The default, if no C language dialect options are given,is-std=gnu23.
The ISO C standard defines (in clause 4) two classes of conformingimplementation. Aconforming hosted implementation supports thewhole standard including all the library facilities; aconformingfreestanding implementation is only required to provide certainlibrary facilities: those in<float.h>,<limits.h>,<stdarg.h>, and<stddef.h>; since AMD1, also those in<iso646.h>; since C99, also those in<stdbool.h> and<stdint.h>; and since C11, also those in<stdalign.h>and<stdnoreturn.h>. In addition, complex types, added in C99, are notrequired for freestanding implementations. Since C23, freestandingimplementations are required to support a larger range of libraryfacilities, including some functions from other headers.
The standard also defines two environments for programs, afreestanding environment, required of all implementations andwhich may not have library facilities beyond those required offreestanding implementations, where the handling of program startupand termination are implementation-defined; and ahostedenvironment, which is not required, in which all the libraryfacilities are provided and startup is through a functionintmain (void) orint main (int, char *[]). An OS kernel is an exampleof a program running in a freestanding environment; a program using the facilities of anoperating system is an example of a program running in a hosted environment.
GCC aims towards being usable as the compiler for a conformingfreestanding or hosted implementation.By default, it acts as the compiler for a hostedimplementation, defining__STDC_HOSTED__ as1 andpresuming that when the names of ISO C functions are used, they havethe semantics defined in the standard. To make it act as the compilerfor a freestanding environment, use theoption-ffreestanding; it then defines__STDC_HOSTED__ to0 and does 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.SeeOptions Controlling C Dialect.
GCC generally provides library facilities in headers that do notdeclare functions with external linkage (which includes the headersrequired by C11 and before to be provided by freestandingimplementations), but not those included in other headers.Additionally, GCC provides<stdatomic.h>, even though itdeclares some functions with external linkage (which are provided inlibatomic). On a few platforms, some of the headers notdeclaring functions with external linkage are instead obtained fromthe OS’s C library, which may mean that they lack support for featuresfrom more recent versions of the C standard that are supported inGCC’s own versions of those headers. On some platforms, GCC provides<tgmath.h> (but this implementation does not support interfacesadded in C23).
To use the facilities of a hosted environment, and some of thefacilities required in a freestanding environment by C23, you need tofind them elsewhere (for example, in the GNU C library).SeeStandard Libraries.
Most of the compiler support routines used by GCC are present inlibgcc, but there are a few exceptions. GCC requires thefreestanding environment providememcpy,memmove,memset andmemcmp. Contrary to the standardscoveringmemcpy GCC expects the case of an exact overlapof source and destination to work and not invoke undefined behavior.Finally, if__builtin_trap is used, and the target doesnot implement thetrap pattern, then GCC emits a calltoabort.
For references to Technical Corrigenda, Rationale documents andinformation concerning the history of C that is available online, seehttps://gcc.gnu.org/readings.html
GCC supports the original ISO C++ standard published in 1998,and the 2011, 2014, 2017 and mostly 2020 and 2024 revisions.
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 (exportis a notable exception) and most of the changes in C++03. To selectthis standard in GCC, use one of the options-ansi,-std=c++98, or-std=c++03; to obtain all the diagnosticsrequired by the standard, you should also specify-pedantic (or-pedantic-errors if you want them to be errors rather thanwarnings).
A revised ISO C++ standard was published in 2011 as ISO/IEC14882:2011, and is referred to as C++11; before its publication it wascommonly referred to as C++0x. C++11 contains several changes to theC++ language, all of which have been implemented in GCC. For detailsseehttps://gcc.gnu.org/projects/cxx-status.html#cxx11.To select this standard in GCC, use the option-std=c++11.
Another revised ISO C++ standard was published in 2014 as ISO/IEC14882:2014, and is referred to as C++14; before its publication it wassometimes referred to as C++1y. C++14 contains several furtherchanges to the C++ language, all of which have been implemented in GCC.For details seehttps://gcc.gnu.org/projects/cxx-status.html#cxx14.To select this standard in GCC, use the option-std=c++14.
The C++ language was further revised in 2017 and ISO/IEC 14882:2017 waspublished. This is referred to as C++17, and before publication wasoften referred to as C++1z. GCC supports all the changes in thatspecification. For further details seehttps://gcc.gnu.org/projects/cxx-status.html#cxx17. Use the option-std=c++17 to select this variant of C++.
Another revised ISO C++ standard was published in 2020 as ISO/IEC14882:2020, and is referred to as C++20; before its publication it wassometimes referred to as C++2a. GCC supports most of the changes in thenew specification. For further details seehttps://gcc.gnu.org/projects/cxx-status.html#cxx20.To select this standard in GCC, use the option-std=c++20.
Yet another revised ISO C++ standard was published in 2024 as ISO/IEC14882:2024, and is referred to as C++23; before its publication it wassometimes referred to as C++2b. GCC supports most of the changes in thenew specification. For further details seehttps://gcc.gnu.org/projects/cxx-status.html#cxx23.To select this standard in GCC, use the option-std=c++23.
More information about the C++ standards is available on the ISO C++committee’s web site athttps://www.open-std.org/jtc1/sc22/wg21/.
To obtain all the diagnostics required by any of the standard versionsdescribed above you should specify-pedanticor-pedantic-errors, otherwise GCC will allow some non-ISO C++features as extensions. SeeOptions to Request or Suppress Warnings.
By default, GCC also provides some additional extensions to the C++ languagethat on rare occasions conflict with the C++ standard. SeeOptions Controlling C++ Dialect. Use of the-std options listed above disables these extensions where theythey conflict with the C++ standard version selected. You may alsoselect an extended version of the C++ language explicitly with-std=gnu++98 (for C++98 with GNU extensions), or-std=gnu++11 (for C++11 with GNU extensions), or-std=gnu++14 (for C++14 with GNU extensions), or-std=gnu++17 (for C++17 with GNU extensions), or-std=gnu++20 (for C++20 with GNU extensions), or-std=gnu++23 (for C++23 with GNU extensions).
The default, ifno C++ language dialect options are given, is-std=gnu++20.
GCC supports “traditional” Objective-C (also known as “Objective-C1.0”) and contains support for the Objective-C exception andsynchronization syntax. It has also support for a number of“Objective-C 2.0” language extensions, including properties, fastenumeration (only for Objective-C), method attributes and the@optional and @required keywords in protocols. GCC supportsObjective-C++ and features available in Objective-C are also availablein Objective-C++.
GCC by default uses the GNU Objective-C runtime library, which is partof GCC and is not the same as the Apple/NeXT Objective-C runtimelibrary used on Apple systems. There are a number of differencesdocumented in this manual. The options-fgnu-runtime and-fnext-runtime allow you to switch between producing outputthat works with the GNU Objective-C runtime library and output thatworks with the Apple/NeXT Objective-C runtime library.
There is no formal written standard for Objective-C or Objective-C++.The authoritative manual on traditional Objective-C (1.0) is“Object-Oriented Programming and the Objective-C Language”(https://www.gnustep.org/resources/documentation/ObjectivCBook.pdf).
The Objective-C exception and synchronization syntax (that is, thekeywords@try,@throw,@catch,@finally and@synchronized) issupported by GCC and is enabled with the option-fobjc-exceptions. The syntax is briefly documented in thismanual and in the Objective-C 2.0 manuals from Apple.
The Objective-C 2.0 language extensions and features are automaticallyenabled; they include properties (via the@property,@synthesize and@dynamic keywords), fast enumeration (not available inObjective-C++), attributes for methods (such asdeprecated,noreturn,sentinel,format),theunused attribute for method arguments, the@package keyword for instance variables and the@optional and@required keywords in protocols. You can disable all theseObjective-C 2.0 language extensions with the option-fobjc-std=objc1, which causes the compiler to recognize thesame Objective-C language syntax recognized by GCC 4.0, and to producean error if one of the new features is used.
GCC has currently no support for non-fragile instance variables.
The authoritative manual on Objective-C 2.0 is available from Apple:
For more information concerning the history of Objective-C that isavailable online, seehttps://gcc.gnu.org/readings.html
As of the GCC 15 release, GCC supports the ISO COBOL language standard(ISO/IEC 1989:2023). It includes some support for compatibility withother COBOL compilers via the-dialect option.
As of the GCC 4.7.1 release, GCC supports the Go 1 language standard,described athttps://go.dev/doc/go1.
GCC supports the D 2.0 programming language. The D language itself iscurrently defined by its reference implementation and supporting languagespecification, described athttps://dlang.org/spec/spec.html.
GCC supports the Modula-2 language and is compliant with the PIM2,PIM3, PIM4 and ISO dialects. Also implemented are a complete set offree ISO libraries. It also contains a collection of PIM librariesand some Logitech compatible libraries.
For more information on Modula-2 seehttps://gcc.gnu.org/readings.html. The online manual isavailable athttps://gcc.gnu.org/onlinedocs/gm2/index.html.
SeeAbout This Guide inGNAT Reference Manual, for information on standardconformance and compatibility of the Ada compiler.
SeeStandards inThe GNU Fortran Compiler, for detailsof standards supported by GNU Fortran.
Next:GCC Command Options, Previous:Programming Languages Supported by GCC, Up:Introduction [Contents][Index]