From ead816e515683271665551037ee6ce431a880b61 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 9 Aug 2014 22:35:24 +0300 Subject: utils: add a STATIC_ASSERT macro It'd be nicer to use C11's static_assert(), but it's easier to roll our own C99 version using a trick I saw in xv6. Signed-off-by: Ran Benita --- src/utils.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index 51d690e..508435d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -40,6 +40,10 @@ */ #define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr)) +#define STATIC_ASSERT(expr, message) do { \ + switch (0) { case 0: case (expr): ; } \ +} while (0) + static inline bool streq(const char *s1, const char *s2) { -- cgit v1.2.1