473,378 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how #include directives are handled

What does the C standard (C99) say about which version of header2.h
should be included in the following case - where directory1 is the
current directory and directory2 is included in the list of directories
to be searched for headers?

contents of directory1:

file1.c:
#include "file1.h"
int main(void) { return 0; }
-- EOF

file1.h:
#include "header1.h"
-- EOF

header2.h:
#warning ---> In directory1/header2.h
-- EOF
contents of directory2:

header1.h:
#include "header2.h"
-- EOF

header2.h:
#warning ---> In directory2/header2.h
-- EOF
Perhaps this is all implemtation defined... if it is what happens
typically in the real world? GCC gives

$ gcc -Iother file1.c
In file included from other/header1.h:1,
from file1.h:2,
from file1.c:2:
other/header2.h:1:2: warning: #warning ---> In other/header2.h

-Charlie

Nov 14 '05 #1
1 1315


Charles Mills wrote:
What does the C standard (C99) say about which version of header2.h
should be included in the following case - where directory1 is the
current directory and directory2 is included in the list of directories
to be searched for headers?
The Standard says it's "implementation-defined," and
that's all.
[...]
Perhaps this is all implemtation defined... if it is what happens
typically in the real world? [...]


You can count on the real world to be variegated, maybe
even chaotic. "There are more things in Heaven and Earth,
Horatio, than are dreamt of in your philosophy." A few
behaviors that I've seen:

- The search path is fixed throughout the compilation,
so every #include traverses the same list of places
in the same order, regardless of where the #include
directive itself resides.

- The search begins where the #include directive is
found, and only if the #include'd file isn't found
there does it search the global path.

- The search begins where the topmost .c file is found,
and then proceeds along the global path if necessary.
The location of the #include directive itself doesn't
matter.

I've even used a system where the notion of "directory"
could itself involve a kind of a search path -- and different
releases of the compiler disagreed on how the location of an
#include in "the same directory" but at different positions
in the implied path were treated ...

Suggestions: Insofar as possible, give every header file
a globally unique name. If that's not possible (on a large
project it often isn't), try to limit the departures to
strictly-local headers that are #include'd only by C sources
in the same directory; avoid nesting references to these
"colliding" headers inside headers that are used in wider
contexts. If even that much isn't possible, try to audit
the set of headers each compilation actually pulls in; gcc,
for example, can tell you exactly which headers it #includes.

--
Er*********@sun.com

Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tom Bates | last post by:
Possible? It seems nobody knows how... :-) Tom
2
by: Mo | last post by:
Hi all, I hope that someone out there can help me with a problem I have been having. I have just finished creating a website and have added a header to most of the pages on my site. The header...
7
by: Chad Scharf | last post by:
I have a legacy ASP application running on IIS 6.0 (Windows Server 2003 Web Edition) that is throwing an error when processesing a certain asp page that has about 200 or so include directives. ...
28
by: Ramesh | last post by:
Hi, I am currently maintaining a legacy code with a very very large code base. I am facing problems with C/C++ files having a lot of un-necessary #includes. On an average every C/C++ file has...
9
by: bill | last post by:
Forget the exact definition of difference between, #include <foo.h> and #include "bar.h" Normally foo.h is a standard header file, so it's path is not defined in compiler option, but I...
4
by: darrel | last post by:
I'm trying to load an include dynamically. So, I'm writing out the include tag via a response.write: response.write("<!--#include virtual='" & contentIncludeFile &"' -->") however, that's...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
2
by: python | last post by:
I'm parsing a text file for a proprietary product that has the following 2 directives: #include <somefile> #define <name<value> Defined constants are referenced via <#name#syntax. I'm...
8
by: thomas | last post by:
priority_queue usually uses the greater<intpredicate function. But as you know, we don't always use priority_queue<int>. Actually we may need the "priority_queue<pair<int,int>,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.