Boost logo

Boost :

From: Glen Knowles (gknowles_at_[hidden])
Date: 2001-11-12 19:36:04


How is the decision to use <assert.h> vs <cassert> made? My impression,
although I have nothing to base it on, was that the <c...> versions of the
includes are to be preferred.

-----Original Message-----
From: Peter Dimov [mailto:pdimov_at_[hidden]]
Sent: Monday, November 12, 2001 5:20 AM
To: Boost List
Subject: [boost] Boost.Assert

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?

--
Peter Dimov
Multi Media Ltd.
#define BOOST_DEBUG
// boost/assert.hpp
#ifdef BOOST_DEBUG
#include <assert.h>
#endif
#ifndef BOOST_ASSERT
#ifdef BOOST_DEBUG
bool boost_error(char const * expr, char const * file, long line);
#ifndef BOOST_ERROR
#define BOOST_ERROR(expr) (expr || !boost_error(#expr, __FILE__, __LINE__))
#endif
#define BOOST_ASSERT(expr) assert(BOOST_ERROR(expr))
#else
#define BOOST_ASSERT ((void)0)
#endif
#endif
//
// user error handler
#include <cstdio>
bool boost_error(char const * expr, char const * file, long line)
{
 std::printf("boost_error(%s, %s, %ld)\n", expr, file, line);
 return true;
}
//
// boost or user code
int main()
{
 BOOST_ASSERT(0 == 1);
}
Info: http://www.boost.org  Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]> 
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



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