Wrapper-Headers.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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-2023 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.7, 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" rel="start" title="Top">
  27. <link href="Index-of-Directives.html" 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" rel="up" title="Header Files">
  30. <link href="System-Headers.html" rel="next" title="System Headers">
  31. <link href="Computed-Includes.html" 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. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.lisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. span.nolinebreak {white-space: nowrap}
  45. span.roman {font-family: initial; font-weight: normal}
  46. span.sansserif {font-family: sans-serif; font-weight: normal}
  47. ul.no-bullet {list-style: none}
  48. -->
  49. </style>
  50. </head>
  51. <body lang="en">
  52. <span id="Wrapper-Headers"></span><div class="header">
  53. <p>
  54. Next: <a href="System-Headers.html" accesskey="n" rel="next">System Headers</a>, Previous: <a href="Computed-Includes.html" accesskey="p" rel="prev">Computed Includes</a>, Up: <a href="Header-Files.html" 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" title="Index" rel="index">Index</a>]</p>
  55. </div>
  56. <hr>
  57. <span id="Wrapper-Headers-1"></span><h3 class="section">2.7 Wrapper Headers</h3>
  58. <span id="index-wrapper-headers"></span>
  59. <span id="index-overriding-a-header-file"></span>
  60. <span id="index-_0023include_005fnext"></span>
  61. <p>Sometimes it is necessary to adjust the contents of a system-provided
  62. header file without editing it directly. GCC&rsquo;s <code>fixincludes</code>
  63. operation does this, for example. One way to do that would be to create
  64. a new header file with the same name and insert it in the search path
  65. before the original header. That works fine as long as you&rsquo;re willing
  66. to replace the old header entirely. But what if you want to refer to
  67. the old header from the new one?
  68. </p>
  69. <p>You cannot simply include the old header with &lsquo;<samp>#include</samp>&rsquo;. That
  70. will start from the beginning, and find your new header again. If your
  71. header is not protected from multiple inclusion (see <a href="Once_002dOnly-Headers.html">Once-Only Headers</a>), it will recurse infinitely and cause a fatal error.
  72. </p>
  73. <p>You could include the old header with an absolute pathname:
  74. </p><div class="example">
  75. <pre class="example">#include &quot;/usr/include/old-header.h&quot;
  76. </pre></div>
  77. <p>This works, but is not clean; should the system headers ever move, you
  78. would have to edit the new headers to match.
  79. </p>
  80. <p>There is no way to solve this problem within the C standard, but you can
  81. use the GNU extension &lsquo;<samp>#include_next</samp>&rsquo;. It means, &ldquo;Include the
  82. <em>next</em> file with this name&rdquo;. This directive works like
  83. &lsquo;<samp>#include</samp>&rsquo; except in searching for the specified file: it starts
  84. searching the list of header file directories <em>after</em> the directory
  85. in which the current file was found.
  86. </p>
  87. <p>Suppose you specify <samp>-I /usr/local/include</samp>, and the list of
  88. directories to search also includes <samp>/usr/include</samp>; and suppose
  89. 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
  90. file contains <code><span class="nolinebreak">#include_next</span>&nbsp;&lt;signal.h&gt;<!-- /@w --></code>, it starts searching
  91. after that directory, and finds the file in <samp>/usr/include</samp>.
  92. </p>
  93. <p>&lsquo;<samp>#include_next</samp>&rsquo; does not distinguish between <code>&lt;<var>file</var>&gt;</code>
  94. and <code>&quot;<var>file</var>&quot;</code> inclusion, nor does it check that the file you
  95. specify has the same name as the current file. It simply looks for the
  96. file named, starting with the directory in the search path after the one
  97. where the current file was found.
  98. </p>
  99. <p>The use of &lsquo;<samp>#include_next</samp>&rsquo; can lead to great confusion. We
  100. recommend it be used only when there is no other alternative. In
  101. particular, it should not be used in the headers belonging to a specific
  102. program; it should be used only to make global corrections along the
  103. lines of <code>fixincludes</code>.
  104. </p>
  105. <hr>
  106. <div class="header">
  107. <p>
  108. Next: <a href="System-Headers.html" accesskey="n" rel="next">System Headers</a>, Previous: <a href="Computed-Includes.html" accesskey="p" rel="prev">Computed Includes</a>, Up: <a href="Header-Files.html" 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" title="Index" rel="index">Index</a>]</p>
  109. </div>
  110. </body>
  111. </html>