Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 1999-08-31 11:19:38


Greg Colvin wrote:

> From: Valentin Bonnard <Bonnard.V_at_[hidden]>
> > ...
> > I propose the following:
> >
> > // precondition: that debug_mode is defined
> > #define BOOST_ASSERT_THROW(condition) \
> > (debug_mode ? boost::Utils::assert_throw(condition, __LINE__,
> > __FILE__) : 0)
> >
> > namespace boost {
> > namespace Utils {
> > struct AssertFailure : std::logic_error {
> > AssertFailure (long line, const char* file);
> > ...
> > };
> >
> > inline void assert_throw (bool c, long line, const char* file)
> > { if (c) throw AssertFailure (line, file); }
> > }
> > using namespace Utils;
> > }
>
> 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.

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.

-- 
Valentin Bonnard

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