Cpts224logo

Debugging – Some Useful Macros


Assert(3)

·       Usage:

#include <assert.h>

void assert(scalar expression);

·       Use assert religiously any time you know certain relationships that MUST hold between variables to another or a variable to a constant.

·       It is helpful for the programmer, not the user.

o  Sample output: “Assertion failed in file foo.c, function do_bar, line 1287”.

·       Leave in your code FOREVER

o  If symbol NDEBUG is defined, the macro goes to nothing.

Simple TRACE macro

More Complex DEBUG Macro