next up previous
Next: Arrays, Pointers, and structs Up: intro_C Previous: Libraries and Header Files

Handy Macro: assert()

The assert() macro is convenient for debugging or bare-bones error trapping. If the argument to assert() is an expression that evaluates ``true'' (non zero) then the statement has no effect. Otherwise execution is halted with a ``failed assert'' message along with a line number indicating where in the source file the failure occurred. To use assert(), simply #include <assert.h> at the beginning of the program. To disable assert()s without physically removing them from the code, compile with the preprocessor option -DNDEBUG or with the preprocessor control statement #define NDEBUG ahead of the #include <assert.h> statement.

Massimo Ricotti 2009-01-26