138 lines
6.9 KiB
HTML
138 lines
6.9 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!-- Copyright (C) 1987-2016 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3 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".
|
|
|
|
This manual contains no Invariant Sections. The Front-Cover Texts are
|
|
(a) (see below), and the Back-Cover Texts are (b) (see below).
|
|
|
|
(a) The FSF's Front-Cover Text is:
|
|
|
|
A GNU Manual
|
|
|
|
(b) The FSF's Back-Cover Text is:
|
|
|
|
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. -->
|
|
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<title>The C Preprocessor: Wrapper Headers</title>
|
|
|
|
<meta name="description" content="The C Preprocessor: Wrapper Headers">
|
|
<meta name="keywords" content="The C Preprocessor: Wrapper Headers">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link href="index.html#Top" rel="start" title="Top">
|
|
<link href="Index-of-Directives.html#Index-of-Directives" rel="index" title="Index of Directives">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="Header-Files.html#Header-Files" rel="up" title="Header Files">
|
|
<link href="System-Headers.html#System-Headers" rel="next" title="System Headers">
|
|
<link href="Computed-Includes.html#Computed-Includes" rel="prev" title="Computed Includes">
|
|
<style type="text/css">
|
|
<!--
|
|
a.summary-letter {text-decoration: none}
|
|
blockquote.smallquotation {font-size: smaller}
|
|
div.display {margin-left: 3.2em}
|
|
div.example {margin-left: 3.2em}
|
|
div.indentedblock {margin-left: 3.2em}
|
|
div.lisp {margin-left: 3.2em}
|
|
div.smalldisplay {margin-left: 3.2em}
|
|
div.smallexample {margin-left: 3.2em}
|
|
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
|
|
div.smalllisp {margin-left: 3.2em}
|
|
kbd {font-style:oblique}
|
|
pre.display {font-family: inherit}
|
|
pre.format {font-family: inherit}
|
|
pre.menu-comment {font-family: serif}
|
|
pre.menu-preformatted {font-family: serif}
|
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
|
pre.smallexample {font-size: smaller}
|
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
|
pre.smalllisp {font-size: smaller}
|
|
span.nocodebreak {white-space:nowrap}
|
|
span.nolinebreak {white-space:nowrap}
|
|
span.roman {font-family:serif; font-weight:normal}
|
|
span.sansserif {font-family:sans-serif; font-weight:normal}
|
|
ul.no-bullet {list-style: none}
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
|
|
<a name="Wrapper-Headers"></a>
|
|
<div class="header">
|
|
<p>
|
|
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> [<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>
|
|
</div>
|
|
<hr>
|
|
<a name="Wrapper-Headers-1"></a>
|
|
<h3 class="section">2.7 Wrapper Headers</h3>
|
|
<a name="index-wrapper-headers"></a>
|
|
<a name="index-overriding-a-header-file"></a>
|
|
<a name="index-_0023include_005fnext"></a>
|
|
|
|
<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>
|
|
<p>You cannot simply include the old header with ‘<samp>#include</samp>’. 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_002dOnly-Headers.html#Once_002dOnly-Headers">Once-Only Headers</a>), it will recurse infinitely and cause a fatal error.
|
|
</p>
|
|
<p>You could include the old header with an absolute pathname:
|
|
</p><div class="smallexample">
|
|
<pre class="smallexample">#include "/usr/include/old-header.h"
|
|
</pre></div>
|
|
<p>This works, but is not clean; should the system headers ever move, you
|
|
would have to edit the new headers to match.
|
|
</p>
|
|
<p>There is no way to solve this problem within the C standard, but you can
|
|
use the GNU extension ‘<samp>#include_next</samp>’. It means, “Include the
|
|
<em>next</em> file with this name”. This directive works like
|
|
‘<samp>#include</samp>’ 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>
|
|
<p>Suppose you specify <samp>-I /usr/local/include</samp>, and the list of
|
|
directories to search also includes <samp>/usr/include</samp>; and suppose
|
|
both directories contain <samp>signal.h</samp>. Ordinary <code>#include <signal.h><!-- /@w --></code> finds the file under <samp>/usr/local/include</samp>. If that
|
|
file contains <code><span class="nolinebreak">#include_next</span> <signal.h><!-- /@w --></code>, it starts searching
|
|
after that directory, and finds the file in <samp>/usr/include</samp>.
|
|
</p>
|
|
<p>‘<samp>#include_next</samp>’ does not distinguish between <code><<var>file</var>></code>
|
|
and <code>"<var>file</var>"</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>
|
|
<p>The use of ‘<samp>#include_next</samp>’ 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>.
|
|
</p>
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
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> [<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>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|