Newsgroups: comp.lang.c++
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: Including header files minimally.
Message-ID: <1988Nov29.203751.26424@utzoo.uucp>
Organization: U of Toronto Zoology
References: <3561@pt.cs.cmu.edu> <7860@nsc.nsc.com> <3614@pt.cs.cmu.edu> <10873@ulysses.homer.nj.att.com> <1073@actnyc.UUCP> <738@quintus.UUCP> <1988Nov25.180309.9323@utzoo.uucp> <8080@nsc.nsc.com> <562@redsox.UUCP>
Date: Tue, 29 Nov 88 20:37:51 GMT

In article <562@redsox.UUCP> campbell@redsox.UUCP (Larry Campbell) writes:
>How portable can something be that's not even implemented yet???  If you
>just wrap your header files [in #ifndef]...
>it achieves the result you desire, completely portably, today, in both
>C++ and C, without requiring changes to preprocessors or funky #pragma
>statements... Really, I think this is a SOLVED PROBLEM ...

Not so.  The problem is that a header wrapped in #ifndef still needs to
be opened, read, and scanned completely every time, which is costly when
the #include relationships are complex and common header files get picked
up many, many times.  One can imagine a tricky compiler which notices
the wrapping and optimizes this case, but that's not going to be easy.

In practice, a header file using "#pragma idempotent" or whatever would
still include the #ifndef wrapper, for the sake of portability.  (There
is no requirement that #pragma be portable, but there *is* a requirement
that ANSI C implementations ignore unrecognized #pragmas.)
-- 
SunOSish, adj:  requiring      |     Henry Spencer at U of Toronto Zoology
32-bit bug numbers.            | uunet!attcan!utzoo!henry henry@zoo.toronto.edu