⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrapper-headers.html

📁 gcc手册
💻 HTML
字号:
<html lang="en">

<head>

<title>The C Preprocessor</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="The C Preprocessor">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

<!--

Copyright &copy; 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,

1997, 1998, 1999, 2000, 2001, 2002, 2003

Free Software Foundation, Inc.



   <p>Permission is granted to copy, distribute and/or modify this document

under the terms of the GNU Free Documentation License, Version 1.1 or

any later version published by the Free Software Foundation.  A copy of

the license is included in the

section entitled "GNU Free Documentation License".



   <p>This manual contains no Invariant Sections.  The Front-Cover Texts are

(a) (see below), and the Back-Cover Texts are (b) (see below).



   <p>(a) The FSF's Front-Cover Text is:



   <p>A GNU Manual



   <p>(b) The FSF's Back-Cover Text is:



   <p>You have freedom to copy and modify this GNU Manual, like GNU

     software.  Copies published by the Free Software Foundation raise

     funds for GNU development. 

-->

</head>

<body>

<div class="node">

<p>

Node:<a name="Wrapper%20Headers">Wrapper Headers</a>,

Next:<a rel="next" accesskey="n" href="System-Headers.html#System%20Headers">System Headers</a>,

Previous:<a rel="previous" accesskey="p" href="Computed-Includes.html#Computed%20Includes">Computed Includes</a>,

Up:<a rel="up" accesskey="u" href="Header-Files.html#Header%20Files">Header Files</a>

<hr><br>

</div>



<h3 class="section">Wrapper Headers</h3>



   <p>Sometimes it is necessary to adjust the contents of a system-provided

header file without editing it directly.  GCC's <code>fixincludes</code>

operation does this, for example.  One way to do that would be to create

a new header file with the same name and insert it in the search path

before the original header.  That works fine as long as you're willing

to replace the old header entirely.  But what if you want to refer to

the old header from the new one?



   <p>You cannot simply include the old header with <code>#include</code>.  That

will start from the beginning, and find your new header again.  If your

header is not protected from multiple inclusion (see <a href="Once-Only-Headers.html#Once-Only%20Headers">Once-Only Headers</a>), it will recurse infinitely and cause a fatal error.



   <p>You could include the old header with an absolute pathname:

<pre class="example">     #include "/usr/include/old-header.h"

     </pre>



<p>This works, but is not clean; should the system headers ever move, you

would have to edit the new headers to match.



   <p>There is no way to solve this problem within the C standard, but you can

use the GNU extension <code>#include_next</code>.  It means, "Include the

<em>next</em> file with this name."  This directive works like

<code>#include</code> except in searching for the specified file: it starts

searching the list of header file directories <em>after</em> the directory

in which the current file was found.



   <p>Suppose you specify <code>-I /usr/local/include</code>, and the list of

directories to search also includes <code>/usr/include</code>; and suppose

both directories contain <code>signal.h</code>.  Ordinary <code>#include&nbsp;&lt;signal.h&gt;</code> finds the file under <code>/usr/local/include</code>.  If that

file contains <code>#include_next&nbsp;&lt;signal.h&gt;</code>, it starts searching

after that directory, and finds the file in <code>/usr/include</code>.



   <p><code>#include_next</code> does not distinguish between <code>&lt;</code><var>file</var><code>&gt;</code>

and <code>"</code><var>file</var><code>"</code> inclusion, nor does it check that the file you

specify has the same name as the current file.  It simply looks for the

file named, starting with the directory in the search path after the one

where the current file was found.



   <p>The use of <code>#include_next</code> can lead to great confusion.  We

recommend it be used only when there is no other alternative.  In

particular, it should not be used in the headers belonging to a specific

program; it should be used only to make global corrections along the

lines of <code>fixincludes</code>.



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -