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();
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().



Peter Dimov
Multi Media Ltd.
// boost/assert.hpp
#include <assert.h>
bool boost_error(char const * expr, char const * file, long line);
#define BOOST_ERROR(expr) (expr || !boost_error(#expr, __FILE__, __LINE__))
#define BOOST_ASSERT(expr) assert(BOOST_ERROR(expr))
#define BOOST_ASSERT ((void)0)
// 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:  Unsubscribe:
Your use of Yahoo! Groups is subject to 

Boost list run by bdawes at, gregod at, cpdaniel at, john at