summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/standards.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/gcc~13/standards.html')
-rw-r--r--devdocs/gcc~13/standards.html10
1 files changed, 10 insertions, 0 deletions
diff --git a/devdocs/gcc~13/standards.html b/devdocs/gcc~13/standards.html
new file mode 100644
index 00000000..a547bf5c
--- /dev/null
+++ b/devdocs/gcc~13/standards.html
@@ -0,0 +1,10 @@
+<div class="chapter-level-extent" id="Standards"> <div class="nav-panel"> <p> Next: <a href="invoking-gcc" accesskey="n" rel="next">GCC Command Options</a>, Previous: <a href="g_002b_002b-and-gcc" accesskey="p" rel="prev">Programming Languages Supported by GCC</a>, Up: <a href="index" accesskey="u" rel="up">Introduction</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="chapter" id="Language-Standards-Supported-by-GCC"><span>2 Language Standards Supported by GCC<a class="copiable-link" href="#Language-Standards-Supported-by-GCC"> ¶</a></span></h1> <p>For each language compiled by GCC for which there is a standard, GCC attempts to follow one or more versions of that standard, possibly with some exceptions, and possibly with some extensions. </p> <ul class="mini-toc"> <li><a href="#C-Language" accesskey="1">C Language</a></li> <li><a href="#C_002b_002b-Language" accesskey="2">C++ Language</a></li> <li><a href="#Objective-C-and-Objective-C_002b_002b-Languages" accesskey="3">Objective-C and Objective-C++ Languages</a></li> <li><a href="#Go-Language" accesskey="4">Go Language</a></li> <li><a href="#D-language" accesskey="5">D language</a></li> <li><a href="#References-for-Other-Languages" accesskey="6">References for Other Languages</a></li> </ul> <div class="section-level-extent" id="C-Language"> <h2 class="section"><span>2.1 C Language<a class="copiable-link" href="#C-Language"> ¶</a></span></h2> <p>The original ANSI C standard (X3.159-1989) was ratified in 1989 and published in 1990. This standard was ratified as an ISO standard (ISO/IEC 9899:1990) later in 1990. There were no technical differences between these publications, although the sections of the ANSI standard were renumbered and became clauses in the ISO standard. The ANSI standard, but not the ISO standard, also came with a Rationale document. This standard, in both its forms, is commonly known as <em class="dfn">C89</em>, or occasionally as <em class="dfn">C90</em>, from the dates of ratification. To select this standard in GCC, use one of the options <samp class="option">-ansi</samp>, <samp class="option">-std=c90</samp> or <samp class="option">-std=iso9899:1990</samp>; to obtain all the diagnostics required by the standard, you should also specify <samp class="option">-pedantic</samp> (or <samp class="option">-pedantic-errors</samp> if you want them to be errors rather than warnings). See <a class="xref" href="c-dialect-options">Options Controlling C Dialect</a>. </p> <p>Errors in the 1990 ISO C standard were corrected in two Technical Corrigenda published in 1994 and 1996. GCC does not support the uncorrected version. </p> <p>An amendment to the 1990 standard was published in 1995. This amendment added digraphs and <code class="code">__STDC_VERSION__</code> to the language, but otherwise concerned the library. This amendment is commonly known as <em class="dfn">AMD1</em>; the amended standard is sometimes known as <em class="dfn">C94</em> or <em class="dfn">C95</em>. To select this standard in GCC, use the option <samp class="option">-std=iso9899:199409</samp> (with, as for other standard versions, <samp class="option">-pedantic</samp> to receive all required diagnostics). </p> <p>A new edition of the ISO C standard was published in 1999 as ISO/IEC 9899:1999, and is commonly known as <em class="dfn">C99</em>. (While in development, drafts of this standard version were referred to as <em class="dfn">C9X</em>.) GCC has substantially complete support for this standard version; see <a class="uref" href="https://gcc.gnu.org/c99status.html">https://gcc.gnu.org/c99status.html</a> for details. To select this standard, use <samp class="option">-std=c99</samp> or <samp class="option">-std=iso9899:1999</samp>. </p> <p>Errors in the 1999 ISO C standard were corrected in three Technical Corrigenda published in 2001, 2004 and 2007. GCC does not support the uncorrected version. </p> <p>A fourth version of the C standard, known as <em class="dfn">C11</em>, was published in 2011 as ISO/IEC 9899:2011. (While in development, drafts of this standard version were referred to as <em class="dfn">C1X</em>.) GCC has substantially complete support for this standard, enabled with <samp class="option">-std=c11</samp> or <samp class="option">-std=iso9899:2011</samp>. A version with corrections integrated was prepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it is known as <em class="dfn">C17</em> and is supported with <samp class="option">-std=c17</samp> or <samp class="option">-std=iso9899:2017</samp>; the corrections are also applied with <samp class="option">-std=c11</samp>, and the only difference between the options is the value of <code class="code">__STDC_VERSION__</code>. </p> <p>A further version of the C standard, known as <em class="dfn">C2X</em>, is under development; experimental and incomplete support for this is enabled with <samp class="option">-std=c2x</samp>. </p> <p>By default, GCC provides some extensions to the C language that, on rare occasions conflict with the C standard. See <a class="xref" href="c-extensions">Extensions to the C Language Family</a>. Some features that are part of the C99 standard are accepted as extensions in C90 mode, and some features that are part of the C11 standard are accepted as extensions in C90 and C99 modes. Use of the <samp class="option">-std</samp> options listed above disables these extensions where they conflict with the C standard version selected. You may also select an extended version of the C language explicitly with <samp class="option">-std=gnu90</samp> (for C90 with GNU extensions), <samp class="option">-std=gnu99</samp> (for C99 with GNU extensions) or <samp class="option">-std=gnu11</samp> (for C11 with GNU extensions). </p> <p>The default, if no C language dialect options are given, is <samp class="option">-std=gnu17</samp>. </p> <p>The ISO C standard defines (in clause 4) two classes of conforming implementation. A <em class="dfn">conforming hosted implementation</em> supports the whole standard including all the library facilities; a <em class="dfn">conforming freestanding implementation</em> is only required to provide certain library facilities: those in <code class="code">&lt;float.h&gt;</code>, <code class="code">&lt;limits.h&gt;</code>, <code class="code">&lt;stdarg.h&gt;</code>, and <code class="code">&lt;stddef.h&gt;</code>; since AMD1, also those in <code class="code">&lt;iso646.h&gt;</code>; since C99, also those in <code class="code">&lt;stdbool.h&gt;</code> and <code class="code">&lt;stdint.h&gt;</code>; and since C11, also those in <code class="code">&lt;stdalign.h&gt;</code> and <code class="code">&lt;stdnoreturn.h&gt;</code>. In addition, complex types, added in C99, are not required for freestanding implementations. </p> <p>The standard also defines two environments for programs, a <em class="dfn">freestanding environment</em>, required of all implementations and which may not have library facilities beyond those required of freestanding implementations, where the handling of program startup and termination are implementation-defined; and a <em class="dfn">hosted environment</em>, which is not required, in which all the library facilities are provided and startup is through a function <code class="code">int
+main (void)</code> or <code class="code">int main (int, char *[])</code>. An OS kernel is an example of a program running in a freestanding environment; a program using the facilities of an operating system is an example of a program running in a hosted environment. </p> <p>GCC aims towards being usable as a conforming freestanding implementation, or as the compiler for a conforming hosted implementation. By default, it acts as the compiler for a hosted implementation, defining <code class="code">__STDC_HOSTED__</code> as <code class="code">1</code> and presuming that when the names of ISO C functions are used, they have the semantics defined in the standard. To make it act as a conforming freestanding implementation for a freestanding environment, use the option <samp class="option">-ffreestanding</samp>; it then defines <code class="code">__STDC_HOSTED__</code> to <code class="code">0</code> and does not make assumptions about the meanings of function names from the standard library, with exceptions noted below. To build an OS kernel, you may well still need to make your own arrangements for linking and startup. See <a class="xref" href="c-dialect-options">Options Controlling C Dialect</a>. </p> <p>GCC does not provide the library facilities required only of hosted implementations, nor yet all the facilities required by C99 of freestanding implementations on all platforms. To use the facilities of a hosted environment, you need to find them elsewhere (for example, in the GNU C library). See <a class="xref" href="standard-libraries">Standard Libraries</a>. </p> <p>Most of the compiler support routines used by GCC are present in <samp class="file">libgcc</samp>, but there are a few exceptions. GCC requires the freestanding environment provide <code class="code">memcpy</code>, <code class="code">memmove</code>, <code class="code">memset</code> and <code class="code">memcmp</code>. Finally, if <code class="code">__builtin_trap</code> is used, and the target does not implement the <code class="code">trap</code> pattern, then GCC emits a call to <code class="code">abort</code>. </p> <p>For references to Technical Corrigenda, Rationale documents and information concerning the history of C that is available online, see <a class="uref" href="https://gcc.gnu.org/readings.html">https://gcc.gnu.org/readings.html</a> </p> </div> <div class="section-level-extent" id="C_002b_002b-Language"> <h2 class="section"><span>2.2 C++ Language<a class="copiable-link" href="#C_002b_002b-Language"> ¶</a></span></h2> <p>GCC supports the original ISO C++ standard published in 1998, and the 2011, 2014, 2017 and mostly 2020 revisions. </p> <p>The original ISO C++ standard was published as the ISO standard (ISO/IEC 14882:1998) and amended by a Technical Corrigenda published in 2003 (ISO/IEC 14882:2003). These standards are referred to as C++98 and C++03, respectively. GCC implements the majority of C++98 (<code class="code">export</code> is a notable exception) and most of the changes in C++03. To select this standard in GCC, use one of the options <samp class="option">-ansi</samp>, <samp class="option">-std=c++98</samp>, or <samp class="option">-std=c++03</samp>; to obtain all the diagnostics required by the standard, you should also specify <samp class="option">-pedantic</samp> (or <samp class="option">-pedantic-errors</samp> if you want them to be errors rather than warnings). </p> <p>A revised ISO C++ standard was published in 2011 as ISO/IEC 14882:2011, and is referred to as C++11; before its publication it was commonly referred to as C++0x. C++11 contains several changes to the C++ language, all of which have been implemented in GCC. For details see <a class="uref" href="https://gcc.gnu.org/projects/cxx-status.html#cxx11">https://gcc.gnu.org/projects/cxx-status.html#cxx11</a>. To select this standard in GCC, use the option <samp class="option">-std=c++11</samp>. </p> <p>Another revised ISO C++ standard was published in 2014 as ISO/IEC 14882:2014, and is referred to as C++14; before its publication it was sometimes referred to as C++1y. C++14 contains several further changes to the C++ language, all of which have been implemented in GCC. For details see <a class="uref" href="https://gcc.gnu.org/projects/cxx-status.html#cxx14">https://gcc.gnu.org/projects/cxx-status.html#cxx14</a>. To select this standard in GCC, use the option <samp class="option">-std=c++14</samp>. </p> <p>The C++ language was further revised in 2017 and ISO/IEC 14882:2017 was published. This is referred to as C++17, and before publication was often referred to as C++1z. GCC supports all the changes in that specification. For further details see <a class="uref" href="https://gcc.gnu.org/projects/cxx-status.html#cxx17">https://gcc.gnu.org/projects/cxx-status.html#cxx17</a>. Use the option <samp class="option">-std=c++17</samp> to select this variant of C++. </p> <p>Another revised ISO C++ standard was published in 2020 as ISO/IEC 14882:2020, and is referred to as C++20; before its publication it was sometimes referred to as C++2a. GCC supports most of the changes in the new specification. For further details see <a class="uref" href="https://gcc.gnu.org/projects/cxx-status.html#cxx20">https://gcc.gnu.org/projects/cxx-status.html#cxx20</a>. To select this standard in GCC, use the option <samp class="option">-std=c++20</samp>. </p> <p>More information about the C++ standards is available on the ISO C++ committee’s web site at <a class="uref" href="http://www.open-std.org/jtc1/sc22/wg21/">http://www.open-std.org/jtc1/sc22/wg21/</a>. </p> <p>To obtain all the diagnostics required by any of the standard versions described above you should specify <samp class="option">-pedantic</samp> or <samp class="option">-pedantic-errors</samp>, otherwise GCC will allow some non-ISO C++ features as extensions. See <a class="xref" href="warning-options">Options to Request or Suppress Warnings</a>. </p> <p>By default, GCC also provides some additional extensions to the C++ language that on rare occasions conflict with the C++ standard. See <a class="xref" href="c_002b_002b-dialect-options">Options Controlling C++ Dialect</a>. Use of the <samp class="option">-std</samp> options listed above disables these extensions where they they conflict with the C++ standard version selected. You may also select an extended version of the C++ language explicitly with <samp class="option">-std=gnu++98</samp> (for C++98 with GNU extensions), or <samp class="option">-std=gnu++11</samp> (for C++11 with GNU extensions), or <samp class="option">-std=gnu++14</samp> (for C++14 with GNU extensions), or <samp class="option">-std=gnu++17</samp> (for C++17 with GNU extensions), or <samp class="option">-std=gnu++20</samp> (for C++20 with GNU extensions). </p> <p>The default, if no C++ language dialect options are given, is <samp class="option">-std=gnu++17</samp>. </p> </div> <div class="section-level-extent" id="Objective-C-and-Objective-C_002b_002b-Languages"> <h2 class="section"><span>2.3 Objective-C and Objective-C++ Languages<a class="copiable-link" href="#Objective-C-and-Objective-C_002b_002b-Languages"> ¶</a></span></h2> <p>GCC supports “traditional” Objective-C (also known as “Objective-C 1.0”) and contains support for the Objective-C exception and synchronization syntax. It has also support for a number of “Objective-C 2.0” language extensions, including properties, fast enumeration (only for Objective-C), method attributes and the @optional and @required keywords in protocols. GCC supports Objective-C++ and features available in Objective-C are also available in Objective-C++. </p> <p>GCC by default uses the GNU Objective-C runtime library, which is part of GCC and is not the same as the Apple/NeXT Objective-C runtime library used on Apple systems. There are a number of differences documented in this manual. The options <samp class="option">-fgnu-runtime</samp> and <samp class="option">-fnext-runtime</samp> allow you to switch between producing output that works with the GNU Objective-C runtime library and output that works with the Apple/NeXT Objective-C runtime library. </p> <p>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”: <a class="uref" href="https://gnustep.github.io/resources/documentation/ObjectivCBook.pdf">https://gnustep.github.io/resources/documentation/ObjectivCBook.pdf</a> is the original NeXTstep document. </p> <p>The Objective-C exception and synchronization syntax (that is, the keywords <code class="code">@try</code>, <code class="code">@throw</code>, <code class="code">@catch</code>, <code class="code">@finally</code> and <code class="code">@synchronized</code>) is supported by GCC and is enabled with the option <samp class="option">-fobjc-exceptions</samp>. The syntax is briefly documented in this manual and in the Objective-C 2.0 manuals from Apple. </p> <p>The Objective-C 2.0 language extensions and features are automatically enabled; they include properties (via the <code class="code">@property</code>, <code class="code">@synthesize</code> and <code class="code">@dynamic keywords</code>), fast enumeration (not available in Objective-C++), attributes for methods (such as <code class="code">deprecated</code>, <code class="code">noreturn</code>, <code class="code">sentinel</code>, <code class="code">format</code>), the <code class="code">unused</code> attribute for method arguments, the <code class="code">@package</code> keyword for instance variables and the <code class="code">@optional</code> and <code class="code">@required</code> keywords in protocols. You can disable all these Objective-C 2.0 language extensions with the option <samp class="option">-fobjc-std=objc1</samp>, which causes the compiler to recognize the same Objective-C language syntax recognized by GCC 4.0, and to produce an error if one of the new features is used. </p> <p>GCC has currently no support for non-fragile instance variables. </p> <p>The authoritative manual on Objective-C 2.0 is available from Apple: </p>
+<ul class="itemize mark-bullet"> <li>
+<a class="uref" href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html">https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html</a> </li>
+</ul> <p>For more information concerning the history of Objective-C that is available online, see <a class="uref" href="https://gcc.gnu.org/readings.html">https://gcc.gnu.org/readings.html</a> </p> </div> <div class="section-level-extent" id="Go-Language"> <h2 class="section"><span>2.4 Go Language<a class="copiable-link" href="#Go-Language"> ¶</a></span></h2> <p>As of the GCC 4.7.1 release, GCC supports the Go 1 language standard, described at <a class="uref" href="https://go.dev/doc/go1">https://go.dev/doc/go1</a>. </p> </div> <div class="section-level-extent" id="D-language"> <h2 class="section"><span>2.5 D language<a class="copiable-link" href="#D-language"> ¶</a></span></h2> <p>GCC supports the D 2.0 programming language. The D language itself is currently defined by its reference implementation and supporting language specification, described at <a class="uref" href="https://dlang.org/spec/spec.html">https://dlang.org/spec/spec.html</a>. </p> </div> <div class="section-level-extent" id="References-for-Other-Languages"> <h2 class="section"><span>2.6 References for Other Languages<a class="copiable-link" href="#References-for-Other-Languages"> ¶</a></span></h2> <p>See <a data-manual="gnat_rm" href="https://gcc.gnu.org/onlinedocs/gnat_rm/index.html#Top">About This Guide</a> in GNAT Reference Manual, for information on standard conformance and compatibility of the Ada compiler. </p> <p>See <a data-manual="gfortran" href="https://gcc.gnu.org/onlinedocs/gfortran/Standards.html#Standards">Standards</a> in The GNU Fortran Compiler, for details of standards supported by GNU Fortran. </p> </div> </div> <div class="nav-panel"> <p> Next: <a href="invoking-gcc">GCC Command Options</a>, Previous: <a href="g_002b_002b-and-gcc">Programming Languages Supported by GCC</a>, Up: <a href="index">Introduction</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
+ <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Standards.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Standards.html</a>
+ </p>
+</div>