Go to the first, previous, next, last section, table of contents.
#define NDEBUG #include <assert.h> assert(expression); assertval(expression);
These macros are used to assist in debugging. The source code includes
references to assert
or assertval
, passing them
expressions that should be true
(non-zero). When the expression
yields false
(zero), a diagnostic message is printed to the
standard error stream, and the program aborts.
If you define the macro NDEBUG
before including `assert.h',
then these assert
and assertval
expand to nothing to
reduce code size after debugging is done.
assert
returns 1 if its argument is non-zero, else it aborts.
assertval
returns the value of its expression argument, if
non-zero, else it aborts.
ANSI (see note 1), POSIX (see note 2)
Notes:
assert
is ANSI, assertval
is not.
assert
is Posix, assertval
is not.
/* Like `strdup', but doesn't crash if the argument is NULL. */ char * safe_strdup(const char *s) { assert(s != 0); return strdup(s); }
Go to the first, previous, next, last section, table of contents.