util: Make assert a no-op on non-debug builds.
This ensures that an assertion like assert(expensive_test()); won't have any penalty on release builds. It also implies that no vital code should be in assert expressions.
This commit is contained in:
parent
77ef705058
commit
7a2271c659
|
@ -181,11 +181,14 @@ void _debug_assert_fail(const char *expr,
|
|||
*
|
||||
* Do not expect that the assert call terminates -- errors must be handled
|
||||
* regardless of assert behavior.
|
||||
*
|
||||
* For non debug builds the assert macro will expand to a no-op, so do not
|
||||
* call functions with side effects in the assert expression.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
|
||||
#else
|
||||
#define debug_assert(expr) ((void)(expr))
|
||||
#define debug_assert(expr) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue