Add UC_ASSERT

This commit is contained in:
Nils O. Selåsdal
2013-03-17 22:13:57 +01:00
parent ad72894380
commit 2e226d561b
+13 -1
View File
@@ -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