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 <ran234@gmail.com>
master
Ran Benita 2014-08-09 22:35:24 +03:00
parent d38ff018b1
commit ead816e515
1 changed files with 4 additions and 0 deletions

View File

@ -40,6 +40,10 @@
*/ */
#define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr)) #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 static inline bool
streq(const char *s1, const char *s2) streq(const char *s1, const char *s2)
{ {