On 20 Oct 2005 11:14:02 -0400,
co****@panix.com (Greg Comeau) wrote in
comp.lang.c++:
In article <11**********************@o13g2000cwo.googlegroups .com>,
paulius-maruska <pa*************@gmail.com> wrote:we*****@yahoo.com wrote: What will happen if header files with the exact same names but with
different contents and declared/defined without include guard reside in
the include path for the compiler?
Are these header files are included more than once? If so, is it the
lastest included file always overwrite the previous one? Is this
behavior predictable?
thanks.
Only the first found file will be included. So it depends on the
compiler where it will look for a file with that name first. Usualy,
compiler looks for includes in the directories specified in INCLUDE
environment variable, in exact the same order as they are specified
there.
It is not tue that only the first found file will be include'd
(see Victor's respoonse). It's also not the case that usually
the path chosen are taken from the INCLUDE environment variable;
some do, but this is completely compiler specific, and most include
other choices too even if they do use INCLUDE.
I think you are wiggling a little bit too much on this one. A
compiler that included more than one file would be completely
non-conforming, since the standard says "the header" and "the source
file".
There is nothing that requires that an implementation select the first
matching header or file it finds in the implementation-defined search,
it could search the relevant space and use the last matching file or
header. If there is more than one matching header or file to be
found, it could arbitrarily select among them randomly or based on
some unspecified criteria.
The only thing the standard will not allow it to do is directly
include more than one header or file because of one #include
directive.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html