Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

137 lines
6.8KB

  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>Wrapper Headers (The C Preprocessor)</title>
  21. <meta name="description" content="Wrapper Headers (The C Preprocessor)">
  22. <meta name="keywords" content="Wrapper Headers (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="Header-Files.html#Header-Files" rel="up" title="Header Files">
  30. <link href="System-Headers.html#System-Headers" rel="next" title="System Headers">
  31. <link href="Computed-Includes.html#Computed-Includes" rel="prev" title="Computed Includes">
  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="Wrapper-Headers"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="System-Headers.html#System-Headers" accesskey="n" rel="next">System Headers</a>, Previous: <a href="Computed-Includes.html#Computed-Includes" accesskey="p" rel="prev">Computed Includes</a>, Up: <a href="Header-Files.html#Header-Files" accesskey="u" rel="up">Header Files</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="Wrapper-Headers-1"></a>
  68. <h3 class="section">2.7 Wrapper Headers</h3>
  69. <a name="index-wrapper-headers"></a>
  70. <a name="index-overriding-a-header-file"></a>
  71. <a name="index-_0023include_005fnext"></a>
  72. <p>Sometimes it is necessary to adjust the contents of a system-provided
  73. header file without editing it directly. GCC&rsquo;s <code>fixincludes</code>
  74. operation does this, for example. One way to do that would be to create
  75. a new header file with the same name and insert it in the search path
  76. before the original header. That works fine as long as you&rsquo;re willing
  77. to replace the old header entirely. But what if you want to refer to
  78. the old header from the new one?
  79. </p>
  80. <p>You cannot simply include the old header with &lsquo;<samp>#include</samp>&rsquo;. That
  81. will start from the beginning, and find your new header again. If your
  82. header is not protected from multiple inclusion (see <a href="Once_002dOnly-Headers.html#Once_002dOnly-Headers">Once-Only Headers</a>), it will recurse infinitely and cause a fatal error.
  83. </p>
  84. <p>You could include the old header with an absolute pathname:
  85. </p><div class="smallexample">
  86. <pre class="smallexample">#include &quot;/usr/include/old-header.h&quot;
  87. </pre></div>
  88. <p>This works, but is not clean; should the system headers ever move, you
  89. would have to edit the new headers to match.
  90. </p>
  91. <p>There is no way to solve this problem within the C standard, but you can
  92. use the GNU extension &lsquo;<samp>#include_next</samp>&rsquo;. It means, &ldquo;Include the
  93. <em>next</em> file with this name&rdquo;. This directive works like
  94. &lsquo;<samp>#include</samp>&rsquo; except in searching for the specified file: it starts
  95. searching the list of header file directories <em>after</em> the directory
  96. in which the current file was found.
  97. </p>
  98. <p>Suppose you specify <samp>-I /usr/local/include</samp>, and the list of
  99. directories to search also includes <samp>/usr/include</samp>; and suppose
  100. both directories contain <samp>signal.h</samp>. Ordinary <code>#include&nbsp;&lt;signal.h&gt;<!-- /@w --></code> finds the file under <samp>/usr/local/include</samp>. If that
  101. file contains <code><span class="nolinebreak">#include_next</span>&nbsp;&lt;signal.h&gt;<!-- /@w --></code>, it starts searching
  102. after that directory, and finds the file in <samp>/usr/include</samp>.
  103. </p>
  104. <p>&lsquo;<samp>#include_next</samp>&rsquo; does not distinguish between <code>&lt;<var>file</var>&gt;</code>
  105. and <code>&quot;<var>file</var>&quot;</code> inclusion, nor does it check that the file you
  106. specify has the same name as the current file. It simply looks for the
  107. file named, starting with the directory in the search path after the one
  108. where the current file was found.
  109. </p>
  110. <p>The use of &lsquo;<samp>#include_next</samp>&rsquo; can lead to great confusion. We
  111. recommend it be used only when there is no other alternative. In
  112. particular, it should not be used in the headers belonging to a specific
  113. program; it should be used only to make global corrections along the
  114. lines of <code>fixincludes</code>.
  115. </p>
  116. <hr>
  117. <div class="header">
  118. <p>
  119. Next: <a href="System-Headers.html#System-Headers" accesskey="n" rel="next">System Headers</a>, Previous: <a href="Computed-Includes.html#Computed-Includes" accesskey="p" rel="prev">Computed Includes</a>, Up: <a href="Header-Files.html#Header-Files" accesskey="u" rel="up">Header Files</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>
  120. </div>
  121. </body>
  122. </html>