From f791c684a3d248baa83a3167086826ba6238d7f5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 25 Dec 2012 11:52:14 +0100 Subject: [PATCH] macro: use C11 static_assert() macro for static assertions --- src/shared/macro.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/shared/macro.h b/src/shared/macro.h index e930fdab533..700171b8324 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)))