Re: curiosity about includes

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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:
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.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: C++0x: Scaling up on weak foundations?
    ... I think backward compatibility is a weak foundation to build upon and the ... Well I'm designing my own language. ... You should prefer to make it not compile instead of fail ... For this purpose there are standard header ...
    (comp.lang.misc)
  • Re: Check for uncompiled code
    ... The compile date, time, flash-compile [ ... internal item header from all processors. ... date, time user, and number of flash frames used (zero if not flash- ... 001 a update date for yupt hdr: ...
    (comp.databases.pick)
  • Re: Forth Frustrations
    ... Traditional Forth compiles the header at the beginning and unsmudges ... data on the control-flow stack you have a colon-sys. ... compile a previous word with the same name, ... switch a compiler back and forth, ...
    (comp.lang.forth)
  • Re: Forcing compile-time error
    ... I am replacing calls to an outdated system function with a new wrapper ... and macro name. ... OldFunction is prototyped in the header files which ... compile error, but for every file that includes the ...
    (comp.lang.c)
  • Re: Forth Frustrations
    ... And when you heard the simple rule that all defining words are followed by the name of the thing being defined, ... where the code starts relative to the header. ... compile a previous word with the same name, ... sense to have the nameless code ready before you start. ...
    (comp.lang.forth)