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