Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2002-12-29 12:50:14


On Sun, 29 Dec 2002 12:22:31 +0100, Alberto Barbati
<abarbati_at_[hidden]> wrote:

>Gennaro Prota wrote:
>> [snip] The fact that it is useful to reduce compilation
>> time is just a result of some compiler writers' attitude to prefer encouraging
>> the use of non-standard features rather than e.g. recognizing the include guard
>> idiom and optimize away the subsequent #includes (as for instance g++ does).
>
>I don't want to start a religion war about which compiler is better or
>smarter or encourages a better style.

Nor do I.

> I agree that recognizing the
>include guard idiom is a good thing, probably the best thing to do for a
>compiler.
>
>Yet I'm stuck with MSVC anyway, as many other programmers out there, and
>#pragma once may have a significant effect on compilation time on that
>compiler.

Hmm... frankly I haven't used it anymore. I'm under the impression
they have fixed it now, but last time I checked it had a lot of bugs.
It was easy, for instance, to end up including the same file twice if
it was reached through different paths (e.g.: #include "subdir/file.h"
in A.cpp and #include "file.h" in subdir/file2.h). Usually one doesn't
notice the error, because he uses both the pragma and the canonical
include guard, but that means of course that the speed gain comes to
nothing. Probably it was VC++ 5.0 though.

> I just suggested a way to allow other compilers (there may be
>fewer than I may think of, obviously) to use the #pragma and also to be
>a little more descriptive. It's just a matter of a three line addition
>in config/compiler/visualc.hpp:
>
>#if _MSC_VER >= 1020
>#define BOOST_HAS_PRAGMA_ONCE
>#endif
>
>for example also Metrowerks CodeWarrior supports #pragma once, so the
>#define could also be added to config/compiler/metrowerks.hpp.

Yes, my intent was not to object the proposal (which I couldn't do
either ;-)) BTW, we are lucky here, because the name "once" is rather
standardized among compiler writers (it would be a mess for boost code
otherwise). In effect, the whole story about file inclusion should be
the other way round: any source file is included at most once for each
TU, unless the programmer requires otherwise ;-)

Genny.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk