standards.texi 13 KB

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