diff options
author | Richard Braun <rbraun@sceen.net> | 2017-12-03 15:14:04 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-12-03 15:14:04 +0100 |
commit | 6440d748b5d09828f3ede954e62d7048fe3250c5 (patch) | |
tree | 58fb6c27f56ca53bcd7c0f0cdd7d2abd6bc81fe6 /include | |
parent | c7d2507fc455421429a531d722947ab415259c77 (diff) |
Make assert have no side effects
Unlike commit d18d0e85596f90e0bd597b33d58209d0b3973c95, this change
silences warnings about unused variables without using the unused
attribute.
Diffstat (limited to 'include')
-rw-r--r-- | include/assert.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/assert.h b/include/assert.h index 8fdc2fe..6aaf292 100644 --- a/include/assert.h +++ b/include/assert.h @@ -21,7 +21,14 @@ #define static_assert _Static_assert #ifdef NDEBUG -#define assert(expression) ((void)(expression)) + +/* + * The assert() macro normally doesn't produce side effects when turned off, + * but this may result in many "set but not used" warnings. Using sizeof() + * silences these warnings without producing side effects. + */ +#define assert(expression) ((void)sizeof(expression)) + #else /* NDEBUG */ #include <kern/macros.h> |