From 2e226d561ba0560572575ad9512d3a959a0bb9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sun, 17 Mar 2013 22:13:57 +0100 Subject: [PATCH] Add UC_ASSERT --- include/ucore/utils.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/ucore/utils.h b/include/ucore/utils.h index 1b3737e..c6f08c1 100644 --- a/include/ucore/utils.h +++ b/include/ucore/utils.h @@ -4,7 +4,7 @@ //Gnerate a compiler error if the compile time //constant expression fails -#define STATIC_ASSERT(expr) \ +#define UC_STATIC_ASSERT(expr) \ do { \ enum { assert_static__ = 1/(expr) }; \ } while (0) @@ -58,5 +58,17 @@ typeof( ((type *)0)->member ) *__mptr = (ptr); \ #define UC_STRINGIFY(x) UC_STRINGIFY_HLP(x) #define UC_STRINGIFY_HLP(x) #x + +/** + * assert() that is not affected by NDEBUG define + */ +#define UC_ASSERT(expr) do {\ +if (!(expr) ) {\ + fprintf(stderr,\ + "UC_ASSERT failed '%s' %s:%d\n", UC_STRINGIFY(expr), __FILE__, __LINE__);\ + uc_backtrace_fd(3);\ + abort();\ +} while (0) + #endif