Re: curiosity about includes
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 26 Mar 2008 12:16:03 -0500
For many years I worked on the principle that every #include file should include
everything it needs to compile correctly. After one disaster about 12 years ago when I
inherited a mess of code where A required B required C required D required E, and also Q
required B, but none of the headers had include guards,... anyway it was a total mess, and
I spent about three days making it sane, only to have the client tell me that "the
compilations are inefficient because you are including files more than once" (never mind
that on my poor old 500MHz machine it would compile in under a minute...AFTER then
changes!) and demanded I "fix" the code back to its original state. After a couple weeks
of arguing, I basically dropped the client, saying I would not work on a project whose
integrity was compromised by antiquated notions of "efficiency" (their lead programmer had
apparently learned on PDP-11s, and was even unhappy that "the preprocessor is always run
even when it isn't needed", and did not understand precompiled headers)
But I've always been disappointed that Microsoft requires the #include order, when it
makes a lot more sense for every view header to include the document header file.
joe
On Wed, 26 Mar 2008 11:58:31 -0400, David Wilkinson <no-reply@xxxxxxxxxxxx> wrote:
asellon wrote:Joseph M. Newcomer [MVP]
I have a project I am working on that is a standard SDI app. I started it
in VS2005 using the wizard, so it has the standard settings from that.
In the view class header, there is a variable pointer to the doc that
provides for the GetDocument() call. Standard stuff.
the curiosity is in the fact that the view header file knows about the
CXXXDoc* without any include or prototype.
How is that?
And further, I wondered about this because I did something that broke this
in another application and had to add the prototype class CXXXDoc to the
view class header in order to get it to compile. But it compiled before I
did "something" without the prototype... so what is the story with this?
asellon:
You will notice that in the Wizard derived code, every .cpp file that includes
CXXXView.h includes CXXXDoc.h before.
IMHO, code that depends on the order of includes is A Bad Thing. In my projects
I usually forward declare CXXXDoc in CXXXView.h, and move the implementation of
GetDocument() to the CXXXView.cpp file.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: curiosity about includes
- From: David Wilkinson
- Re: curiosity about includes
- From: Ajay Kalra
- Re: curiosity about includes
- References:
- curiosity about includes
- From: asellon
- Re: curiosity about includes
- From: David Wilkinson
- curiosity about includes
- Prev by Date: Re: How do you declare a Global Variable in VC++6
- Next by Date: Re: static library
- Previous by thread: Re: curiosity about includes
- Next by thread: Re: curiosity about includes
- Index(es):
Relevant Pages
|