Boost logo

Boost :

From: Don Waugaman (dpw_at_[hidden])
Date: 2001-07-03 12:24:45


On Tue, Jul 03, 2001 at 01:14:24PM -0400, Jeff Paquette wrote:
> ----- Original Message -----
> From: "David Abrahams" <david.abrahams_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Tuesday, July 03, 2001 12:50 PM
> Subject: Re: [boost] Suggested coding guidelines
>
>
> >
> > ----- Original Message -----
> > From: "Jeff Paquette" <paquette_at_[hidden]>
> >
> > > Include guards can and are also used to prevent the header from being
> > > reparsed (as suggested by Lakos). As such, it (IMHO) would be better if
> > the
> > > guard referenced the file name.
> > >
> > > I'd rather write:
> > >
> > > #if !defined(BOOST_XXX)
> > > #include "boost/xxx"
> > > #endif
> > >
> > > than
> > >
> > > #if !defined("68C2D2A0-6FD1-11d5-8F0C-00105AC8B6E1")
> > > #include "boost/xxx"
> > > #endif
> >
> > This practice is unreliable with most headers. For example, you can't do
> > that with your system headers if you're writing portable code. Most
> standard
> > and 3rd party libraries don't document their #include guard conventions,
> so
> > you have to look inside the header to determine what guard they used --
> and
> > there's no guarantee they won't change it.
>
> The argument is not about standard headers, is it? How many of us do that?
>
> > We could of course establish such a convention with boost headers, but I
> am
> > unconvinced of the benefits.
> >
> > Finally, many modern compilers have learned to recognize #include guards
> > such that this functionality is automated and you get zero benefit from
> > cluttering files with such checks.
>
> Interesting! Could you cite some examples? MSVC's "#pragma once" doesn't
> count.

GCC is one such compiler. Every time an include file is read in, the
conditional which will keep it from being read again (if any) is memorized
by the preprocessor, and if the condition is true when another #include
for that file comes along, the file will not even be opened.

And since I was confused in my previous email to the list, I'd agree with
Dave that external include guards (the Lakos scheme) should not be used,
but I'd keep my stance that the preprocessor symbol which guards the file
should have some relationship, however tenuous, with the file name.

-- 
    - Don Waugaman (dpw_at_[hidden])    O-             _|_  Will pun
Web Page: http://www.cs.arizona.edu/people/dpw/            |   for food
In the Sonoran Desert, where we say: "It's a dry heat..."  |     <><
Oh, I know it's a penny here and a penny there, but look at me.  I worked
myself up from nothing to a state of extreme poverty.    -- Groucho Marx

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