Re: #include what?

"Russ Cox" <rsc@swtch.com>
26 Apr 2006 01:13:11 -0400

          From comp.compilers

Related articles
#include what? DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-04-25)
Re: #include what? rsc@swtch.com (Russ Cox) (2006-04-26)
Re: #include what? ian@airs.com (Ian Lance Taylor) (2006-04-27)
Re: #include what? cfc@shell01.TheWorld.com (Chris F Clark) (2006-04-27)
Re: #include what? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-04-28)
Re: #include what? anton@mips.complang.tuwien.ac.at (2006-04-28)
Re: #include what? cfc@shell01.TheWorld.com (Chris F Clark) (2006-04-30)
Re: #include what? DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-05-09)
| List of all articles for this month |
From: "Russ Cox" <rsc@swtch.com>
Newsgroups: comp.compilers
Date: 26 Apr 2006 01:13:11 -0400
Organization: Compilers Central
References: 06-04-148
Keywords: C
Posted-Date: 26 Apr 2006 01:13:11 EDT

> [The C standards say that the interpretation of the <filename> or
> "filename" in #include is entirely up to the implementation. My
> impression is that the de-facto standard on Unix systems is whatever
> cccp, the GCC preprocessor, does. -John]


For #include <foo> gcc searches the -I directories you've specified,
then the standard system include directories.


For #include "foo" gcc searches the directory containing the current
file and then falls back to the <foo> rules.


There are various subtleties that no one should ever want to know
about some -I options that gcc accepts, but the above is the basics
that you can depend on from most compilers. As Join pointed out,
the C standard doesn't say anything about where to search,
but it does require that "foo" searches fall back to <foo> if whatever
early extra searching "" implies doesn't turn anything up.


#includenext, which is even-more gcc-specific, makes gcc start the search
where the search for the current file left off. This way you could
create your own wrapper around (say) <stdio.h> that was actually
called stdio.h and did something like


#includenext <stdio.h>
void newfunction(FILE*);


Using includenext keeps gcc from finding the current file again.
I can't imagine why you would ever use this.


Russ


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.