The Standard C Library
, P. J. Plauger
Page 19, beginning on pharagraph 4.
This header has an additional peculiarity. As I mentioned in the previous
chapter, all other headers are idempotent. Including any of them two or
more times has the same effect as including teh header just once. In the case
, however, its behavior can vary each time you include it. The
header alters the definition of assert
to agree with the current definition
status of NDEBUG
The net effect is that you can control assertions in different ways
throughout a source file. Performance may suffer dramatically, for exam-
ple, when assertions occur inside frequently executed loops. Or an earlier
assertion may terminate execution before you get to the revealing parts. In
either case, you may need to turn assertions on and off at various places
throughout a source file.
So to turn assertions on, you write:
And to turn assertions off, you write:
Note that you can safely define the macro NDEBUG
even if it is already
defined. It is a benign redefinition, as I described on page 12. Benign
redefinition was added to Standard C for just this purpose. It eliminates
the need to protect multiple definitions of the same macro with macro
guards and conditional directives.