Boost logo

Boost :

From: Dan W. (danw_at_[hidden])
Date: 2004-01-02 18:19:26


While talking about Invariants, DBC, assertions and exceptions in
another thread, the subject came up of how useless assert() appears to
be, in that it terminates the program.
What I always do in my coding is to have a global function...

void landing_strip()
{
   nop();
   nop();
   nop();
}

... defining my own assert() that calls it upon evaluating to false, and
placing a break in the middle nop(); (3 for breaking distance :)

I thought of using a coded break within my assert, but opted not to
because that might slow down execution in the debugger (having too many
break addresses to compare at each step).

In this way, instead of terminating, the code stops at the landing
strip, and all I have to do is click on the previous stack level to get
back to the caller. Works like a charm, and I bet I'm not the only one
using this trick.

Would it make sense to generalize this and offer it as an alternative to
the standard assert()? Maybe call it "ensure()"?

dan


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