From 0b6ad46369eb6f3e830c317bb763066069cf0056 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 16 Jun 2016 12:05:01 +0000 Subject: [PATCH] Introduce ASSERT() and BUILD_BUG_ON() Signed-off-by: Andrew Cooper --- include/xtf/lib.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/xtf/lib.h b/include/xtf/lib.h index 183db0f..ddb9f98 100644 --- a/include/xtf/lib.h +++ b/include/xtf/lib.h @@ -21,6 +21,15 @@ void __noreturn panic(const char *fmt, ...) __printf(1, 2); +#define ASSERT(cond) \ + do { if ( !(cond) ) \ + panic("ASSERT(%s) failed at %s:%u\n", \ + #cond, __FILE__, __LINE__); \ + } while ( 0 ) + +#define BUILD_BUG_ON(cond) \ + _Static_assert(!cond, "!(" #cond ")") + void heapsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *), void (*swap)(void *, void *)); -- 2.39.5