From: Lennart Poettering Date: Tue, 25 Dec 2012 10:52:14 +0000 (+0100) Subject: macro: use C11 static_assert() macro for static assertions X-Git-Tag: v197~80 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=f791c684a3d248baa83a3167086826ba6238d7f5 macro: use C11 static_assert() macro for static assertions --- diff --git a/src/shared/macro.h b/src/shared/macro.h index e930fdab5..700171b83 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)))