#include statement format

C

charles hamm

When I generate a new class with VS.NET/C++, the #include statement
that VS puts in the .cpp file to reference the .h file uses ".\" as
the directory spec. My understanding of Windows directory specs
indicates that this is superflous. Is there something I am missing?
 
G

Gabest

When I generate a new class with VS.NET/C++, the #include statement
that VS puts in the .cpp file to reference the .h file uses ".\" as
the directory spec. My understanding of Windows directory specs
indicates that this is superflous. Is there something I am missing?

Moreover, it really likes to re-add it even if there was an include
"something.h" already, without the leading .\ ! My cpp files usually start
like this:

#include "something.h"
#include ".\something.h"
 
M

Mihai N.

It means "do not look in any of the %INCLUDE% directories, but look just
in the current directory".
I am not sure this is the case, but if it is, this is one of the MS things.

The rules are clear (since K&R):

#include "filename.h" // includes from the current folder only
#include <filename.h> // includes from the current folder only
// or from %INCLUDE%

MS always did search in the INCLUDE paths for "...", but it seems that
Dev. Studio .NET (2002 & 2003) does not do it anymore.
In general, Dev.Studio.NET is much nicer in following the standards.
 
J

James Curran

Ummm.. No.

http://msdn.microsoft.com/library/d...ng/html/_predir_The_.23.include_Directive.asp

#include "filename.h" // Looks in current directory, then from %INCLUDE%
#include <filename.h> // looks in %INCLUDE% only.

And, I pretty sure that K&R takes no stand on the matter at all.

The ISO C & C++ Standards (which appear to be identical on this matter) say
only that searching is implementation defined, and that the "filename.h"
must do the same search as the <filename.h> form, but may do a different
search first.


--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
 
M

Mihai N.

#include "filename.h" // Looks in current directory, then from %INCLUDE%
#include <filename.h> // looks in %INCLUDE% only.
The ISO C & C++ Standards (which appear to be identical on this matter) say
only that searching is implementation defined, and that the "filename.h"
must do the same search as the <filename.h> form, but may do a different
search first.

True. Checked it and you are right.

I did switch to Dev. Studio .NET a while ago and I did forgot what Dev.
Studio 6 was doing wrong.

It was looking in the current folder even for #include <...>.
Otherwise it was correct.

And now Dev. Studio NET is 100% correct.
 

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

Top