assert
7-23
Run-Time-Support Functions
Insert Diagnostic Information Macro
assert
Syntax
#include <assert.h>
void
assert
(int expr);
Defined in
assert.h as a macro
Description
The assert macro tests an expression; depending upon the value of the
expression, assert either issues a message and aborts execution or continues
execution. This macro is useful for debugging.
-
If expr is false, the assert macro writes information about the call that failed
to the standard output and aborts execution.
-
If expr is true, the assert macro does nothing.
The header file that defines the assert macro refers to another macro,
NDEBUG. If you have defined NDEBUG as a macro name when the assert.h
header is included in the source file, then the assert macro is defined to have
no effect.
If NDEBUG is not defined when assert.h is included, the assert macro is
defined to test the expression and, if false, write a diagnostic message includ-
ing the source filename, line number, and test of expression.
The assert macro is defined with the printf function, which is not included in the
library. To use assert, you must do one of the following:
-
provide your own version of printf
-
modify assert to output the message by other means.
Example
In this example, an integer i is divided by another integer j. Since dividing by
0 is an illegal operation, the example uses the assert macro to test j before the
division. If j = = 0 assert issues a message and aborts the program.
int i, j;
assert(j);
q = i/j;
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...