header files

C

cwc5w

//x.cpp
#include <h1>
#include "h2"

which directory will C++ first look for when including h1? h2?

Thanks!
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

//x.cpp
#include <h1>
#include "h2"

which directory will C++ first look for when including h1? h2?

For <h1> it's implementation-dependent, for "h2" it's the same
directory as the file the #include-line is in.
 
G

Greg

Erik said:
For <h1> it's implementation-dependent, for "h2" it's the same
directory as the file the #include-line is in.

The search order for h1 and h2 is implementation-defined in either case
- and is usually user-configurable as well. The expectation is that h1
is a standard system header file and will be found in a directory such
as /usr/include (on a UNIXish OS) or the equivalent. The other header
file, h2, should be a header file that belongs to the the program under
development or one of its supporting libraries.

Greg
 
K

Kevin Rouge

Greg said:
The search order for h1 and h2 is implementation-defined in either case
- and is usually user-configurable as well. The expectation is that h1
is a standard system header file and will be found in a directory such
as /usr/include (on a UNIXish OS) or the equivalent. The other header
file, h2, should be a header file that belongs to the the program under
development or one of its supporting libraries.

Greg

In syntax terms, the quotes asks the compiler to first search the current
build folder for the header file. Then, if not found, it searches the c++
header directories for the header. When using "<>", it specifically
searches the c++ header directories.

You can add additional directories to the header's directories list, but
this depends on your platform and c++ compiler.
 
P

Pete Becker

Kevin said:
In syntax terms, the quotes asks the compiler to first search the current
build folder for the header file. Then, if not found, it searches the c++
header directories for the header. When using "<>", it specifically
searches the c++ header directories.

That's often what's implemented, but the requirements are far less
specific. <> says to search for a header (not necessarily contained in a
file) in an implementation-defined manner. "" says to search for a
source file in an implementation-defined manner, and if none is found,
search as if the delimiters had been <>.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
B

Bo Persson

Kevin said:
In syntax terms, the quotes asks the compiler to first search the
current build folder for the header file. Then, if not found, it
searches the c++ header directories for the header. When using
"<>", it specifically searches the c++ header directories.

That is entirely implementation specific.

The real difference is that names in <> specifies a header that does not
even have to be a file (it could be built into the compiler, for example).

Names in "" are mapped to a file, in some way, and searched for in an
implementation defined way.
You can add additional directories to the header's directories
list, but this depends on your platform and c++ compiler.

Note that the standard doesn't require that there are any directories (some
systems doesn't have any), or that the standard headers are stored as files.


Bo Persson
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top