Boost logo

Boost :

From: brianjparker_at_[hidden]
Date: 2001-11-12 20:16:46


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> See the code at the end for my proposed implementation of
BOOST_ASSERT.
>
> Design goals:
>
> * Simple;
> * Off by default;
> * User customizable.
>
> Modes of operation include:
>
> 1. off; when BOOST_DEBUG is not defined.
> 2. simply use assert(); with -DBOOST_DEBUG and -
DBOOST_ASSERT=assert.
> 3. invoke user error handler (boost_error), then assert();
> with -DBOOST_DEBUG.
> 3a. log error and throw.
> 3b. log error and continue.
> 3c. log error and assert().
> 3d. log error and terminate (whole process or current thread only.)
> 3e. perform cleanup and assert().
>
> etc.
>
> Comments?

I think that having a wrapper for assert() such as BOOST_ASSERT()
available that is controlled by a separate switch (BOOST_DEBUG) would
be a useful addition to Boost, because it then allows one to control
independently whether the checked version of Boost is used. The
checked version of certain libaries in Boost could conceivable be too
slow with assertions enabled to be useful for routine use, even in a
debug build. In fact, I would anticipate that large sublibraries of
Boost would define their own macro (e.g. BOOST_ASSERT_GRAPH &
BOOST_DEBUG_GRAPH) to further control this.

Perhaps BOOST_ASSERT should only be off by default when NDEBUG is
defined and on by default in a debug build.

However, I'm not sure I see the advantage in the extra functionality
that is provided over the (standard) assert().
The extra functionality that can be provided in the error handler
(e.g. throwing an exception, continuing etc.) can not be relied upon
as the assertions will be disabled in the release build. In fact,
allowing user code to be called in an assertion will lead to subtle
bugs in release builds when such code is disabled.

This just leaves the additional functionality as an aid to debugging,
but that is surely just a quality-of-implementation issue. Under
Windows,with VC++, the support for assert() is spectacular- in a GUI
application a dialogue box is provided that (optionally) allows one
to call up the JIT debugger and jump to the assertion with a full
stack trace. If the debugging support under other platforms is not
adequate then the solution is to write a better assert() for that
platform, not to provide a replacement assert implementation for
other platforms that don't require it.

(Also, of course, the documentation for BOOST_ASSERT should make it
clear that it is for use in implementing Boost libraries only and is
not intended as a general-purpose tool, for which unadorned assert()
is adequate.)

,Brian Parker


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