[Main]
Title=Wrapper Headers
Index=#include_next

[Top]
Sometimes it is necessary to adjust the contents of a system-provided
header file without editing it directly (although it is not very likely that
this feature will ever be used in TIGCC).  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?
<BR><BR>
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="$$LINK(SEC8)">Once-Only
Headers</A>), it will recurse infinitely and cause a fatal error.
<BR><BR>
You could include the old header with an absolute pathname:
<PRE>#include &quot;/usr/include/old-header.h&quot;
</PRE>
This works, but is not clean; should the system headers ever move, you
would have to edit the new headers to match.
<BR><BR>
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, &quot;Include the
<I>next</I> file with this name.&quot;  This directive works like
<CODE>#include</CODE> except in searching for the specified file: it starts
searching the list of header file directories <I>after</I> the directory
in which the current file was found.
<BR><BR>
Suppose you specify <B>'-I /usr/local/include'</B>, 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
&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>.
<BR><BR>
<CODE>#include_next</CODE> does not distinguish between <CODE>&lt;<I>file</I>&gt;</CODE>
and <CODE>&quot;<I>file</I>&quot;</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.
<BR><BR>
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>.
