Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 1999-08-31 12:27:39


Greg Colvin wrote:
>
> From: Valentin Bonnard <Bonnard.V_at_[hidden]>
> > Greg Colvin wrote:
> > >
> > > From: Valentin Bonnard <Bonnard.V_at_[hidden]>
> > > > Greg Colvin wrote:
> > > > > ...
> > > > > So any user of Boost must define exactly one extern debug_mode in
> > > > > order to link?
> > > >
> > > > Yes. They must declare it in every TU which uses my macro
> > > > before uses of the macro.
> > >
> > > Which means in every translation unit that includes any Boost header?
> >
> > If Boost uses this macro in headers (not just .cc files), then
> > yes.
>
> Ouch.
>
> > > > There is no no-checks-by-default behaviour (there is no
> > > > default behaviour at all).
> > > >
> > > > They can use an static constant but it isn't recommanded.
> > > > They can use an auto variable.
> > > > > And being a link-time constant, the code for the condition cannot
> > > > > be compiled away?
> > > >
> > > > You do it as you want: compile time constant, ``link time''
> > > > constant, or even a variable. It's up to you.
> > > >
> > > > I recommend a compile-time constant with external linkage.
> > >
> > > You mean in each translation unit you would put something like this?
> > >
> > > const debug_mode = MY_DEBUG;
> >
> > (const bool I guess)
> > I recommended a constant with *external* linkage.
>
> Like so?
>
> extern const bool debug_mode = MY_DEBUG;

Yes

> > > Doesn't that break the ODR? Or am I confused again?
> >
> > If MY_DEBUG is defined the same way in all headers, it's
> > fine. If not, _and_ you are using headers which use the
> > macro, then it breaks the ODR.
>
> How do you square that with 3.2, paragraph 3:
>
> Every program shall contain exactly one definition of every non-inline
> function or object that is used in that program; no diagnostic
> required.

debug_mode should be defined in only one .cpp file

> > I leave the responsabillity to define debug_mode
> > consistently to the user.
>
> Then I fail to see how this facility is superior to assert, except
> for throwing

Because:
- it let the user
  - use a global debug_mode, initialised once, with no risk
    at all, or
  - have one debug_mode.hpp header, with no redundancy
- it provides more granularity (debug_mode might have not
  class scope)

I am merely giving my ideas, I am criticizing other's ideas,
I am _not_ promoting anything.

-- 
Valentin Bonnard

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