assert() is a great thing to use while you're developing an application; you can check to see if your code is doing anything really bizarre without wasting a lot of time on parameter checking. Of course, you shouldn't be using asserts instead of error checking...
This nicer GUI assert was inspired by an article by Bruce D. Rosenblum in the December 1997 issue of Dr. Dobb's Journal (issue #272, Improve Your Programming with Asserts).
#include "Ch/ChAssert.h" ... void foo( char *str ) { ASSERT( str != NULL, "NULL string passed to foo()" ); ... // do stuff with str }
All you have to do to use the ChAssert is include the Ch/ChAssert.h header, and then sprinkle ASSERT() calls through your code.
ASSERT( condition, message );
condition is anything you can put in a C/C++ if() statement, and message is a string message that'll be displayed for the hapless user of your debug-enabled code.
Note: message must be at least an empty string (e.g., ""), not NULL.
The beauty of this is that you don't have to remove all the ASSERT() calls when you want to release your code; just define libCh_NODEBUG, NDEBUG or NODEBUG and all the ASSERT() calls will be optimized away.
NDEBUG is the symbol used by the standard ANSI C <assert.h> version of assert().
When an ASSERT() is triggered, the user gets a dialog box that looks something like this:
At this point, the calling thread is blocked (other threads might still be running though) and the user can select Continue to keep going despite the error, or Quit to bail out of the application.
Note that Quit isn't very nice about tearing down the application; it calls the POSIX exit() function right away.
Please see the libCh Overview for licensing information.
Last modified: $Date: 1998/04/11 19:41:01 $