#include -- double quotes vs. angle brackets

B

bartek

Hi,

I'm aware that both quoted and angle-bracketed strings in an #include
directive result in implementation-defined file lookup, differing in the
fact that #include "foo.h" first checks *something* and then falls back to
the same behaviour as #include <foo.h>.

Now, in reality #include <foo.h> generally results in file name being
checked up in explicitly specified locations (-I command line options,
system header locations), while the double quoted version gets the current
directory checked first.

My question is:
- Is that the current working directory? E.g. the directory from which the
compiler is being run.
- Or, the directory where the file with the said #include directive being
parsed is lying?

What's the common behaviour?

Cheers.
 
U

Unforgiven

bartek said:
My question is:
- Is that the current working directory? E.g. the directory from
which the compiler is being run.
- Or, the directory where the file with the said #include directive
being parsed is lying?

The latter is common. The former would make not much sense, since
application-specific header files are rarely in the same directory as the
compiler.

Also note that, at least in Windows, the current working directory need not
actually be the directory that contains the executable. The compiler might
change the current working directory to the location of the compiled source
file, and then look for the header file in the working directory, resulting
in the same behaviour as option 2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top