The <assert.h>
header defines the assert()
macro, which is used for debugging purposes. It also refers to another macro, NDEBUG
, which is defined elsewhere.
Functions and Macros
assert Macro
Purpose
Outputs a diagnostic message to standard errorand stops the program if a test fails.
Prototype
assert (
condition
)
Parameters
-
→ condition
- An expression to test; if the result of the expression is
false
, the diagnostic message is displayed and the program terminates. If the result istrue
, this macro has no effect.
Example
In the following example, the program will terminate if the data buffer could not be allocated.
char *buffer = malloc(150); assert(buffer);