diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-12-25 11:52:14 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-12-31 21:24:26 +0100 |
commit | f791c684a3d248baa83a3167086826ba6238d7f5 (patch) | |
tree | c3c57a1b1f27e2ced8d3f42f1285db079e20e39d | |
parent | 31c15e20ceda62997e84c7e048f65a6dabc5d597 (diff) |
macro: use C11 static_assert() macro for static assertions
-rw-r--r-- | src/shared/macro.h | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h index e930fdab53..700171b832 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -119,14 +119,21 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { log_assert_failed_unreachable(t, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ } while (false) -#define assert_cc(expr) \ - do { \ - switch (0) { \ - case 0: \ - case !!(expr): \ - ; \ - } \ +#if defined(static_assert) +#define assert_cc(expr) \ + do { \ + static_assert(expr, #expr); \ } while (false) +#else +#define assert_cc(expr) \ + do { \ + switch (0) { \ + case 0: \ + case !!(expr): \ + ; \ + } \ + } while (false) +#endif #define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p))) #define UINT_TO_PTR(u) ((void*) ((uintptr_t) (u))) |