assert(3C)
_________________________________________________________________
assert macro
Provide runtime assertions.
_________________________________________________________________
Calling Sequence
#include <assert.h>
#include <stdio.h>
assert(expression);
Description
If the expression is false at runtime, the program terminates,
and C writes a message on the standard error file. The message
includes the name of the source file that was compiled, the line
number, and page number (if greater than one).
The assert macro causes a stack traceback if the expression is
false, and calls the exit function with an argument of 2 to
terminate the program.
If you define the macro NDEBUG before the include file, C will
omit the assertion.
Returns
The assert macro does not return a value.
Related Functions
See also the exit function.
Example
/* Program test for the assert macro */
#include <assert.h>
#include <stdio.h>
main() {
int val = 1, val2 = 0;
assert(val == 1);
printf("Assertion was true.\n\n");
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
assert(3C)
assert(val2 == 1);
}
The above program generates the output
Assertion was true.
Assertion failed: file test.c, line 14
ERROR 74247.
from $traceback in task 1 (unique task id is 1).
A stack traceback then follows.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)