You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
5.3KB

  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>__has_include (The C Preprocessor)</title>
  21. <meta name="description" content="__has_include (The C Preprocessor)">
  22. <meta name="keywords" content="__has_include (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="Conditional-Syntax.html#Conditional-Syntax" rel="up" title="Conditional Syntax">
  30. <link href="Deleted-Code.html#Deleted-Code" rel="next" title="Deleted Code">
  31. <link href="_005f_005fhas_005fbuiltin.html#g_t_005f_005fhas_005fbuiltin" rel="prev" title="__has_builtin">
  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="g_t_005f_005fhas_005finclude"></a>
  62. <div class="header">
  63. <p>
  64. Previous: <a href="_005f_005fhas_005fbuiltin.html#g_t_005f_005fhas_005fbuiltin" accesskey="p" rel="prev"><code>__has_builtin</code></a>, Up: <a href="Conditional-Syntax.html#Conditional-Syntax" accesskey="u" rel="up">Conditional Syntax</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="g_t_005f_005fhas_005finclude-1"></a>
  68. <h4 class="subsection">4.2.9 <code>__has_include</code></h4>
  69. <a name="index-_005f_005fhas_005finclude"></a>
  70. <p>The special operator <code>__has_include (<var>operand</var>)</code> may be used in
  71. &lsquo;<samp>#if</samp>&rsquo; and &lsquo;<samp>#elif</samp>&rsquo; expressions to test whether the header referenced
  72. by its <var>operand</var> can be included using the &lsquo;<samp>#include</samp>&rsquo; directive. Using
  73. the operator in other contexts is not valid. The <var>operand</var> takes
  74. the same form as the file in the &lsquo;<samp>#include</samp>&rsquo; directive (see <a href="Include-Syntax.html#Include-Syntax">Include Syntax</a>) and evaluates to a nonzero value if the header can be included and
  75. to zero otherwise. Note that that the ability to include a header doesn&rsquo;t
  76. imply that the header doesn&rsquo;t contain invalid constructs or &lsquo;<samp>#error</samp>&rsquo;
  77. directives that would cause the preprocessor to fail.
  78. </p>
  79. <p>The <code>__has_include</code> operator by itself, without any <var>operand</var> or
  80. parentheses, acts as a predefined macro so that support for it can be tested
  81. in portable code. Thus, the recommended use of the operator is as follows:
  82. </p>
  83. <div class="smallexample">
  84. <pre class="smallexample">#if defined __has_include
  85. # if __has_include (&lt;stdatomic.h&gt;)
  86. # include &lt;stdatomic.h&gt;
  87. # endif
  88. #endif
  89. </pre></div>
  90. <p>The first &lsquo;<samp>#if</samp>&rsquo; test succeeds only when the operator is supported
  91. by the version of GCC (or another compiler) being used. Only when that
  92. test succeeds is it valid to use <code>__has_include</code> as a preprocessor
  93. operator. As a result, combining the two tests into a single expression
  94. as shown below would only be valid with a compiler that supports the operator
  95. but not with others that don&rsquo;t.
  96. </p>
  97. <div class="smallexample">
  98. <pre class="smallexample">#if defined __has_include &amp;&amp; __has_include (&quot;header.h&quot;) /* not portable */
  99. &hellip;
  100. #endif
  101. </pre></div>
  102. </body>
  103. </html>