Hi All,
When we include a header file, we will use

#include "xxx "

or

#include "xxx"

What's the difference?

Best regards,
Boki.

Re: what's the different between #incldue " xxx" and #include <xxx > by Carl

Carl
Mon Jun 06 23:41:42 CDT 2005

boki wrote:
> Hi All,
> When we include a header file, we will use
>
> #include "xxx "
>
> or
>
> #include "xxx"
>
> What's the difference?

#include "file.h" will locate file.h in the same directory as the including
file, while <file.h> won't.

-cd



Re: what's the different between #incldue " xxx" and #include <xxx > by William

William
Mon Jun 06 23:42:30 CDT 2005

"boki" <bokiteam@ms21.hinet.net> wrote in message
news:edpw9gxaFHA.3040@TK2MSFTNGP14.phx.gbl...
> What's the difference?

Take a look at this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_predir_the_.23.include_directive.asp

It includes this explanation:

<quote>
Quoted form This form instructs the preprocessor to look for include files
in the same directory of the file that contains the #include statement, and
then in the directories of any files that include (#include) that file. The
preprocessor then searches along the path specified by the /I compiler
option, then along paths specified by the INCLUDE environment variable.


Angle-bracket form This form instructs the preprocessor to search for
include files first along the path specified by the /I compiler option,
then, when compiling from the command line, along the path specified by the
INCLUDE environment variable.
<quote>

If there is something in the explanation that you don't understand you can
post again.

Regards,
Will





Re: what's the different between #incldue " xxx" and #include <xxx > by Doug

Doug
Mon Jun 06 23:51:18 CDT 2005

On Tue, 7 Jun 2005 12:20:26 +0800, boki wrote:

> Hi All,
> When we include a header file, we will use
>
> #include "xxx "
>
> or
>
> #include "xxx"
>
> What's the difference?

It's implementation-defined. VC++ implements very sensible rules that make
me think of namespaces. You can find them here:

The #include Directive
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/prepr_8.asp

I use the quoted form for files in my project, and more generally, whenever
I #include a file I can locate relative to the file that contains the
#include. I use the angle bracket form for system headers, and more
generally, headers that are located by consulting the INCLUDE environment
variable or the corresponding IDE setting.

Tip: If you're writing a library, structure your public headers like this:

LibRoot
LibName
Header files, subdirs, etc.

Your users then enter "LibRoot" into INCLUDE, and they #include your
library headers like this:

#include <LibName/header1.h>
#include <LibName/subdir/header2.h>

If LibName is sufficiently unique, then multiple libraries from different
authors can coexist in the same LibRoot directory. Alternatively, you can
make LibRoot unique and use it as your own personal library area, but then
you should put the parent directory of LibRoot into INCLUDE and refer to
headers like this:

#include <LibRoot/LibName/header1.h>

If you don't have a unique path to your headers, you may find yourself in a
situation where order of INCLUDE entries matters, and that's to be avoided.

--
Doug Harrison
Microsoft MVP - Visual C++

Re: what's the different between #incldue " xxx" and #include <xxx by Roland

Roland
Tue Jun 07 02:11:55 CDT 2005

Hi boki,

although the previous posters quite correctly explained
what difference it makes with VC++ to use the "" or <> form
of the #include directive, they completely fail to explain
WHY there are two different forms in the first place.
This all originates in the C++ standard.
The "" version dates all back to the days C was invented
and means in short "include the given files here" using an
implementation defined search sequence for the file name
between the "".
The <> version is quite different. Avoiding the legalese of
the standard it means that the char sequence between the
brackets does NOT necessarily denote a file name. It says
that it "uniquely identifies a header" in a implementation
defined way. This could for example mean that the identifier
between <> is an index into a database and the header fetched
from there.
I think the rationale behind this was, that on some operation
system it might be illegal to use filenames without extensions
or that there might be a restriction in the length of filenames.
For example #include <exception> might be an illegal filename
(it is on DOS). The creators of the standard wanted to make shure
that a program that includes the headers as defined in the standard
to correctly compile on all platforms without changes. So, a DOS
compiler could lookup the <exception> in the example in a file,
find the filename "exceptio.hhh" and then use this filename instead.

VC++ implementation of the <> is completely conforming to the
standard but I wouldn't use the <> form for anything else but
the headers of the standard library, as you might be in for a
big surprise if you switch compilers and use the <> as simply
a means for including files with a different search sequence.

Regards,
Roland

Re: what's the different between #incldue " xxx" and #include <xxx > by Sergei

Sergei
Tue Jun 07 02:43:42 CDT 2005

"Roland Frank" <roland.frank.no-spam@gmx.info> wrote:

> Hi boki,
>
> although the previous posters quite correctly explained
> what difference it makes with VC++ to use the "" or <> form
> of the #include directive, they completely fail to explain
> WHY there are two different forms in the first place.
> This all originates in the C++ standard.
> The "" version dates all back to the days C was invented
> and means in short "include the given files here" using an
> implementation defined search sequence for the file name
> between the "".

I remember the <> version was there when I programmed in C

> The <> version is quite different. Avoiding the legalese of
> the standard it means that the char sequence between the
> brackets does NOT necessarily denote a file name. It says
> that it "uniquely identifies a header" in a implementation
> defined way. This could for example mean that the identifier
> between <> is an index into a database and the header fetched
> from there.
> I think the rationale behind this was, that on some operation
> system it might be illegal to use filenames without extensions
> or that there might be a restriction in the length of filenames.
> For example #include <exception> might be an illegal filename
> (it is on DOS).

It is a legal DOS filename.

Sergei

> The creators of the standard wanted to make shure
> that a program that includes the headers as defined in the standard
> to correctly compile on all platforms without changes. So, a DOS
> compiler could lookup the <exception> in the example in a file,
> find the filename "exceptio.hhh" and then use this filename instead.
>
> VC++ implementation of the <> is completely conforming to the
> standard but I wouldn't use the <> form for anything else but
> the headers of the standard library, as you might be in for a
> big surprise if you switch compilers and use the <> as simply
> a means for including files with a different search sequence.
>
> Regards,
> Roland

Re: what's the different between #incldue " xxx" and #include <xxx > by Sergei

Sergei
Tue Jun 07 03:25:09 CDT 2005

"Sergei" <sergei@nospam.summertime.mtu-net.ru> wrote:
> "Roland Frank" <roland.frank.no-spam@gmx.info> wrote:
>
> > Hi boki,
> >
> > although the previous posters quite correctly explained
> > what difference it makes with VC++ to use the "" or <> form
> > of the #include directive, they completely fail to explain
> > WHY there are two different forms in the first place.
> > This all originates in the C++ standard.
> > The "" version dates all back to the days C was invented
> > and means in short "include the given files here" using an
> > implementation defined search sequence for the file name
> > between the "".
>
> I remember the <> version was there when I programmed in C
>
> > The <> version is quite different. Avoiding the legalese of
> > the standard it means that the char sequence between the
> > brackets does NOT necessarily denote a file name. It says
> > that it "uniquely identifies a header" in a implementation
> > defined way. This could for example mean that the identifier
> > between <> is an index into a database and the header fetched
> > from there.
> > I think the rationale behind this was, that on some operation
> > system it might be illegal to use filenames without extensions
> > or that there might be a restriction in the length of filenames.
> > For example #include <exception> might be an illegal filename
> > (it is on DOS).
>
> It is a legal DOS filename.

Pardon, I see now that it's 9 char long.

Sergei

> Sergei
>
> > The creators of the standard wanted to make shure
> > that a program that includes the headers as defined in the standard
> > to correctly compile on all platforms without changes. So, a DOS
> > compiler could lookup the <exception> in the example in a file,
> > find the filename "exceptio.hhh" and then use this filename instead.
> >
> > VC++ implementation of the <> is completely conforming to the
> > standard but I wouldn't use the <> form for anything else but
> > the headers of the standard library, as you might be in for a
> > big surprise if you switch compilers and use the <> as simply
> > a means for including files with a different search sequence.
> >
> > Regards,
> > Roland

Re: what's the different between #incldue " xxx" and #include <xxx by Roland

Roland
Tue Jun 07 05:12:14 CDT 2005

Hello Sergei,

>>
>>I remember the <> version was there when I programmed in C
>>

You are right, but in C it worked like VC++ implements it today:
Don't look up the file in the source files directory first, but
it still defined the character sequence between the brackets to
be a filename.
C++ dropped this filename business completely and made the transition
between the character sequence between the <> and the actual header
completely implementation defined. It extreme cases it could mean,
that all standard headers could be stored in a database instead of
files - or to be included my magic alltogether. Or your compiler
could lookup <> headers over the internet and download them everytime
(only for your good of course).....


>>It is a legal DOS filename.
>
>
> Pardon, I see now that it's 9 char long.

Those who can count have an advantage sometimes :-)

Regards,
Roland

Re: what's the different between #incldue " xxx" and #include <xxx > by Doug

Doug
Tue Jun 07 11:35:44 CDT 2005

On Tue, 07 Jun 2005 09:11:55 +0200, Roland Frank wrote:

> Hi boki,
>
> although the previous posters quite correctly explained
> what difference it makes with VC++ to use the "" or <> form
> of the #include directive, they completely fail to explain
> WHY there are two different forms in the first place.
> This all originates in the C++ standard.
> The "" version dates all back to the days C was invented
> and means in short "include the given files here" using an
> implementation defined search sequence for the file name
> between the "".
> The <> version is quite different. Avoiding the legalese of
> the standard it means that the char sequence between the
> brackets does NOT necessarily denote a file name. It says
> that it "uniquely identifies a header" in a implementation
> defined way. This could for example mean that the identifier
> between <> is an index into a database and the header fetched
> from there.

The same thing applies to the "" form; compilers fall back on the <> form
if the "" form fails or simply isn't supported.

> I think the rationale behind this was, that on some operation
> system it might be illegal to use filenames without extensions
> or that there might be a restriction in the length of filenames.
> For example #include <exception> might be an illegal filename
> (it is on DOS). The creators of the standard wanted to make shure
> that a program that includes the headers as defined in the standard
> to correctly compile on all platforms without changes. So, a DOS
> compiler could lookup the <exception> in the example in a file,
> find the filename "exceptio.hhh" and then use this filename instead.

Correct. The compiler can map names in #include directives directly to
physical filenames, indirectly by performing some transformation on the
filename (e.g. translating path separators), to arrays of text representing
the header contents stored in the compiler itself, etc.

> VC++ implementation of the <> is completely conforming to the
> standard but I wouldn't use the <> form for anything else but
> the headers of the standard library, as you might be in for a
> big surprise if you switch compilers and use the <> as simply
> a means for including files with a different search sequence.

You might also be in for a big surprise if you use the "" form for third
party library headers that don't use sufficiently unique names. That's also
true for the <> form, but at least you don't have to worry about choosing
globally unique names for the headers you create yourself. (Macro guards
are another story, of course!) Again, this is all implementation-defined,
but the implementation I've seen most commonly is what I described in my
earlier message, with "" to refer to files located relative to the file
making the #include, and <> for everything else. It's the most sensible
approach to take; for example, gcc does it this way, too:

http://www.ugcs.caltech.edu/info/gcc/cpp_2.html#SEC8

As does Sun:

http://docs.sun.com/source/819-0494/sun.specific.html#pgfId-1004269

To minimize the danger of conflicting filenames, apply the approach I
described in my earlier message.

--
Doug Harrison
Microsoft MVP - Visual C++