# NDEBUG Macro

A macro used by <assert.h> to specify the operation of certain debugging features.

Value

This macro is not defined by <assert.h> and must be defined by the user.

Remarks

NDEBUG must be defined as a macro by the user if and when required. Use the #define preprocessor directive to define the macro. It does not need to define any replacement string.

If the macro is defined at the point where <assert.h> is included, it disables certain debugging functionality of the header content supplied by that inclusion, in particular, the assert() macro (assert Macro). The NDEBUG macro may be undefined to allow <assert.h> to be included in subsequent code and with the full debugging functionality provided.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

int main(void)
{
int a;

a = 4;
#define NDEBUG        /* negate debugging - disable assert() functionality */
#include <assert.h>
assert(a == 6);     /* no action performed, even though expression is false */

#undef NDEBUG         /* ensure assert() is active */
#include <assert.h>
a = 7;
assert(a == 7);     /* true - no action performed */
assert(a == 8);     /* false - print message and abort */
}

Example Output

sampassert.c:14 a == 8 -- assertion failed
ABRT