選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Standard-Predefined-Macros.html 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1987-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation. A copy of
  7. the license is included in the
  8. section entitled "GNU Free Documentation License".
  9. This manual contains no Invariant Sections. The Front-Cover Texts are
  10. (a) (see below), and the Back-Cover Texts are (b) (see below).
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Standard Predefined Macros (The C Preprocessor)</title>
  21. <meta name="description" content="Standard Predefined Macros (The C Preprocessor)">
  22. <meta name="keywords" content="Standard Predefined Macros (The C Preprocessor)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Index-of-Directives.html#Index-of-Directives" rel="index" title="Index of Directives">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Predefined-Macros.html#Predefined-Macros" rel="up" title="Predefined Macros">
  30. <link href="Common-Predefined-Macros.html#Common-Predefined-Macros" rel="next" title="Common Predefined Macros">
  31. <link href="Predefined-Macros.html#Predefined-Macros" rel="prev" title="Predefined Macros">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Standard-Predefined-Macros"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Common-Predefined-Macros.html#Common-Predefined-Macros" accesskey="n" rel="next">Common Predefined Macros</a>, Up: <a href="Predefined-Macros.html#Predefined-Macros" accesskey="u" rel="up">Predefined Macros</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Standard-Predefined-Macros-1"></a>
  68. <h4 class="subsection">3.7.1 Standard Predefined Macros</h4>
  69. <a name="index-standard-predefined-macros_002e"></a>
  70. <p>The standard predefined macros are specified by the relevant
  71. language standards, so they are available with all compilers that
  72. implement those standards. Older compilers may not provide all of
  73. them. Their names all start with double underscores.
  74. </p>
  75. <dl compact="compact">
  76. <dt><code>__FILE__</code></dt>
  77. <dd><p>This macro expands to the name of the current input file, in the form of
  78. a C string constant. This is the path by which the preprocessor opened
  79. the file, not the short name specified in &lsquo;<samp>#include</samp>&rsquo; or as the
  80. input file name argument. For example,
  81. <code>&quot;/usr/local/include/myheader.h&quot;</code> is a possible expansion of this
  82. macro.
  83. </p>
  84. </dd>
  85. <dt><code>__LINE__</code></dt>
  86. <dd><p>This macro expands to the current input line number, in the form of a
  87. decimal integer constant. While we call it a predefined macro, it&rsquo;s
  88. a pretty strange macro, since its &ldquo;definition&rdquo; changes with each
  89. new line of source code.
  90. </p></dd>
  91. </dl>
  92. <p><code>__FILE__</code> and <code>__LINE__</code> are useful in generating an error
  93. message to report an inconsistency detected by the program; the message
  94. can state the source line at which the inconsistency was detected. For
  95. example,
  96. </p>
  97. <div class="smallexample">
  98. <pre class="smallexample">fprintf (stderr, &quot;Internal error: &quot;
  99. &quot;negative string length &quot;
  100. &quot;%d at %s, line %d.&quot;,
  101. length, __FILE__, __LINE__);
  102. </pre></div>
  103. <p>An &lsquo;<samp>#include</samp>&rsquo; directive changes the expansions of <code>__FILE__</code>
  104. and <code>__LINE__</code> to correspond to the included file. At the end of
  105. that file, when processing resumes on the input file that contained
  106. the &lsquo;<samp>#include</samp>&rsquo; directive, the expansions of <code>__FILE__</code> and
  107. <code>__LINE__</code> revert to the values they had before the
  108. &lsquo;<samp>#include</samp>&rsquo; (but <code>__LINE__</code> is then incremented by one as
  109. processing moves to the line after the &lsquo;<samp>#include</samp>&rsquo;).
  110. </p>
  111. <p>A &lsquo;<samp>#line</samp>&rsquo; directive changes <code>__LINE__</code>, and may change
  112. <code>__FILE__</code> as well. See <a href="Line-Control.html#Line-Control">Line Control</a>.
  113. </p>
  114. <p>C99 introduced <code>__func__</code>, and GCC has provided <code>__FUNCTION__</code>
  115. for a long time. Both of these are strings containing the name of the
  116. current function (there are slight semantic differences; see the GCC
  117. manual). Neither of them is a macro; the preprocessor does not know the
  118. name of the current function. They tend to be useful in conjunction
  119. with <code>__FILE__</code> and <code>__LINE__</code>, though.
  120. </p>
  121. <dl compact="compact">
  122. <dt><code>__DATE__</code></dt>
  123. <dd><p>This macro expands to a string constant that describes the date on which
  124. the preprocessor is being run. The string constant contains eleven
  125. characters and looks like <code>&quot;Feb&nbsp;12&nbsp;1996&quot;<!-- /@w --></code>. If the day of the
  126. month is less than 10, it is padded with a space on the left.
  127. </p>
  128. <p>If GCC cannot determine the current date, it will emit a warning message
  129. (once per compilation) and <code>__DATE__</code> will expand to
  130. <code>&quot;???&nbsp;??&nbsp;????&quot;<!-- /@w --></code>.
  131. </p>
  132. </dd>
  133. <dt><code>__TIME__</code></dt>
  134. <dd><p>This macro expands to a string constant that describes the time at
  135. which the preprocessor is being run. The string constant contains
  136. eight characters and looks like <code>&quot;23:59:01&quot;</code>.
  137. </p>
  138. <p>If GCC cannot determine the current time, it will emit a warning message
  139. (once per compilation) and <code>__TIME__</code> will expand to
  140. <code>&quot;??:??:??&quot;</code>.
  141. </p>
  142. </dd>
  143. <dt><code>__STDC__</code></dt>
  144. <dd><p>In normal operation, this macro expands to the constant 1, to signify
  145. that this compiler conforms to ISO Standard C. If GNU CPP is used with
  146. a compiler other than GCC, this is not necessarily true; however, the
  147. preprocessor always conforms to the standard unless the
  148. <samp>-traditional-cpp</samp> option is used.
  149. </p>
  150. <p>This macro is not defined if the <samp>-traditional-cpp</samp> option is used.
  151. </p>
  152. <p>On some hosts, the system compiler uses a different convention, where
  153. <code>__STDC__</code> is normally 0, but is 1 if the user specifies strict
  154. conformance to the C Standard. CPP follows the host convention when
  155. processing system header files, but when processing user files
  156. <code>__STDC__</code> is always 1. This has been reported to cause problems;
  157. for instance, some versions of Solaris provide X Windows headers that
  158. expect <code>__STDC__</code> to be either undefined or 1. See <a href="Invocation.html#Invocation">Invocation</a>.
  159. </p>
  160. </dd>
  161. <dt><code>__STDC_VERSION__</code></dt>
  162. <dd><p>This macro expands to the C Standard&rsquo;s version number, a long integer
  163. constant of the form <code><var>yyyy</var><var>mm</var>L</code> where <var>yyyy</var> and
  164. <var>mm</var> are the year and month of the Standard version. This signifies
  165. which version of the C Standard the compiler conforms to. Like
  166. <code>__STDC__</code>, this is not necessarily accurate for the entire
  167. implementation, unless GNU CPP is being used with GCC.
  168. </p>
  169. <p>The value <code>199409L</code> signifies the 1989 C standard as amended in
  170. 1994, which is the current default; the value <code>199901L</code> signifies
  171. the 1999 revision of the C standard; the value <code>201112L</code>
  172. signifies the 2011 revision of the C standard; the value
  173. <code>201710L</code> signifies the 2017 revision of the C standard (which is
  174. otherwise identical to the 2011 version apart from correction of
  175. defects). An unspecified value larger than <code>201710L</code> is used for
  176. the experimental <samp>-std=c2x</samp> and <samp>-std=gnu2x</samp> modes.
  177. </p>
  178. <p>This macro is not defined if the <samp>-traditional-cpp</samp> option is
  179. used, nor when compiling C++ or Objective-C.
  180. </p>
  181. </dd>
  182. <dt><code>__STDC_HOSTED__</code></dt>
  183. <dd><p>This macro is defined, with value 1, if the compiler&rsquo;s target is a
  184. <em>hosted environment</em>. A hosted environment has the complete
  185. facilities of the standard C library available.
  186. </p>
  187. </dd>
  188. <dt><code>__cplusplus</code></dt>
  189. <dd><p>This macro is defined when the C++ compiler is in use. You can use
  190. <code>__cplusplus</code> to test whether a header is compiled by a C compiler
  191. or a C++ compiler. This macro is similar to <code>__STDC_VERSION__</code>, in
  192. that it expands to a version number. Depending on the language standard
  193. selected, the value of the macro is
  194. <code>199711L</code> for the 1998 C++ standard,
  195. <code>201103L</code> for the 2011 C++ standard,
  196. <code>201402L</code> for the 2014 C++ standard,
  197. <code>201703L</code> for the 2017 C++ standard,
  198. or an unspecified value strictly larger than <code>201703L</code> for the
  199. experimental languages enabled by <samp>-std=c++2a</samp> and
  200. <samp>-std=gnu++2a</samp>.
  201. </p>
  202. </dd>
  203. <dt><code>__OBJC__</code></dt>
  204. <dd><p>This macro is defined, with value 1, when the Objective-C compiler is in
  205. use. You can use <code>__OBJC__</code> to test whether a header is compiled
  206. by a C compiler or an Objective-C compiler.
  207. </p>
  208. </dd>
  209. <dt><code>__ASSEMBLER__</code></dt>
  210. <dd><p>This macro is defined with value 1 when preprocessing assembly
  211. language.
  212. </p>
  213. </dd>
  214. </dl>
  215. <hr>
  216. <div class="header">
  217. <p>
  218. Next: <a href="Common-Predefined-Macros.html#Common-Predefined-Macros" accesskey="n" rel="next">Common Predefined Macros</a>, Up: <a href="Predefined-Macros.html#Predefined-Macros" accesskey="u" rel="up">Predefined Macros</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html#Index-of-Directives" title="Index" rel="index">Index</a>]</p>
  219. </div>
  220. </body>
  221. </html>