From: Greg Colvin (gcolvin_at_[hidden])
Date: 1999-08-31 12:01:41
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
> > > 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.
extern const bool debug_mode = MY_DEBUG;
> > 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
The exceptions in 3.2, paragraph 5, seem not to apply.
> 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 a logic error (which might be "handled" and missed)
instead of calling abort (which is harder to ignore), and the
imposition of declaring debug_mode.
> Yes, it's pretty easy to break the ODR by defining an
> constant with external linkage with different values
> in different TUes. At least, in this case, the bug is
> with the definition of debug_mode, not with the macro.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk