-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathassert2.h
More file actions
27 lines (23 loc) · 1.11 KB
/
assert2.h
File metadata and controls
27 lines (23 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* #including this file, instead of the 'usual' <assert.h>, will
cause assert()s to always be evaluated, even in non-debug mode.
This is useful if
-- you really do always want to evaluate the assertions; or
-- you have variables that are only used in the assert()s, and
which result in "unused variable" warnings in NDEBUG mode. (Or, with
the usual -Werror flag, errors.)
Such warnings/errors can be ugly to code around. If the assert() in
question is inexpensive (not evaluated inside a performance-intensive
loop), it may be easier to force the assert() to be evaluated, causing
the warning or error to go away.
The ideal thing would be to have an assert_even_in_debug() function or
macro. This would be useful if, for example, the assert() is evaluated
frequently enough to be a performance issue. At present, I don't have that
problem; if I eventually do, I may re-visit this bit of code. */
#ifdef NDEBUG /* assert() would not normally be compiled */
#define TEMP_NDEBUG NDEBUG
#undef NDEBUG
#include <assert.h>
#define NDEBUG TEMP_NDEBUG
#else
#include <assert.h>
#endif