Wrapper-Headers.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>The C Preprocessor: Wrapper Headers</title>
  20. <meta name="description" content="The C Preprocessor: Wrapper Headers">
  21. <meta name="keywords" content="The C Preprocessor: Wrapper Headers">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Wrapper-Headers"></a>
  63. <div class="header">
  64. <p>
  65. 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>
  66. </div>
  67. <hr>
  68. <a name="Wrapper-Headers-1"></a>
  69. <h3 class="section">2.7 Wrapper Headers</h3>
  70. <a name="index-wrapper-headers"></a>
  71. <a name="index-overriding-a-header-file"></a>
  72. <a name="index-_0023include_005fnext"></a>
  73. <p>Sometimes it is necessary to adjust the contents of a system-provided
  74. header file without editing it directly. GCC&rsquo;s <code>fixincludes</code>
  75. operation does this, for example. One way to do that would be to create
  76. a new header file with the same name and insert it in the search path
  77. before the original header. That works fine as long as you&rsquo;re willing
  78. to replace the old header entirely. But what if you want to refer to
  79. the old header from the new one?
  80. </p>
  81. <p>You cannot simply include the old header with &lsquo;<samp>#include</samp>&rsquo;. That
  82. will start from the beginning, and find your new header again. If your
  83. 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.
  84. </p>
  85. <p>You could include the old header with an absolute pathname:
  86. </p><div class="smallexample">
  87. <pre class="smallexample">#include &quot;/usr/include/old-header.h&quot;
  88. </pre></div>
  89. <p>This works, but is not clean; should the system headers ever move, you
  90. would have to edit the new headers to match.
  91. </p>
  92. <p>There is no way to solve this problem within the C standard, but you can
  93. use the GNU extension &lsquo;<samp>#include_next</samp>&rsquo;. It means, &ldquo;Include the
  94. <em>next</em> file with this name&rdquo;. This directive works like
  95. &lsquo;<samp>#include</samp>&rsquo; except in searching for the specified file: it starts
  96. searching the list of header file directories <em>after</em> the directory
  97. in which the current file was found.
  98. </p>
  99. <p>Suppose you specify <samp>-I /usr/local/include</samp>, and the list of
  100. directories to search also includes <samp>/usr/include</samp>; and suppose
  101. 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
  102. file contains <code><span class="nolinebreak">#include_next</span>&nbsp;&lt;signal.h&gt;<!-- /@w --></code>, it starts searching
  103. after that directory, and finds the file in <samp>/usr/include</samp>.
  104. </p>
  105. <p>&lsquo;<samp>#include_next</samp>&rsquo; does not distinguish between <code>&lt;<var>file</var>&gt;</code>
  106. and <code>&quot;<var>file</var>&quot;</code> inclusion, nor does it check that the file you
  107. specify has the same name as the current file. It simply looks for the
  108. file named, starting with the directory in the search path after the one
  109. where the current file was found.
  110. </p>
  111. <p>The use of &lsquo;<samp>#include_next</samp>&rsquo; can lead to great confusion. We
  112. recommend it be used only when there is no other alternative. In
  113. particular, it should not be used in the headers belonging to a specific
  114. program; it should be used only to make global corrections along the
  115. lines of <code>fixincludes</code>.
  116. </p>
  117. <hr>
  118. <div class="header">
  119. <p>
  120. 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>
  121. </div>
  122. </body>
  123. </html>