9.2. DiagnosticsWhile you are debugging programs, it is often useful to
check that the value of an expression is the one that you
expected. The In order to use #include <assert.h> void assert(int expression) If the expression evaluates to zero (i.e. false) then
assert(1 == 2); /* Might result in */ Assertion failed: 1 == 2, file silly.c, line 15
#define NDEBUG
#include <assert.h>
void
func(void)
{
int c;
assert((c = getchar()) != EOF);
putchar(c);
}Example 9.2Note that assert returns no value. |
The C BookThis book is published as a matter of historical interest. Please read the copyright and disclaimer information. GBdirect Ltd provides up-to-date training and consultancy in C, Embedded C, C++ and a wide range of other subjects based on open standards if you happen to be interested. |
|
West Yorkshire Office
GBdirect Ltd
Training: 0800 651 0338 Please call between 0900 and 1700 (UK time) on Monday to Friday South East Regional Office
GBdirect Ltd
Training: 0800 651 0338 Please call between 0900 and 1700 (UK time) on Monday to Friday Please note: |