From 4c058db338ff00e0e97cea0e985625deb47143cd Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Fri, 18 Dec 2015 21:11:46 +0000 Subject: Add assert.h for asserting some conditions --- assert.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 assert.h diff --git a/assert.h b/assert.h new file mode 100644 index 0000000..08d84f5 --- /dev/null +++ b/assert.h @@ -0,0 +1,46 @@ +#ifndef __ASSERT_H +#define __ASSERT_H + +/***************************************************************************** + * CONFIG ASSERT THINGS + *****************************************************************************/ + +/* enable to enable asserts */ +#define ASSERT_ON + +/* exit way */ +#define __EXIT_ABBORT + +#ifdef __EXIT_ABBORT + #define __EXIT_WAY exit(1); +#else + #define __EXIT_WAY ; +#endif + + +#ifdef ASSERT_ON +#define __STR(S) #S +#define AS_NULL(X) if ((X)==NULL)\ +{\ + printf("\033[1;34m%s:%d GOTCHA NULL\033[0m\n",__FILE__,__LINE__);\ + __EXIT_WAY;\ +} + +#define AS_RANGE(X,A,B) + +#define AS_EXPR(X) if ((X))\ +{\ + printf("\033[1;34m%s:%d assert:%s\033[0m\n",__FILE__,__LINE__,__STR(X));\ + __EXIT_WAY;\ +} + +#else + +#define AS_NULL(X) +#define AS_RANGE(X,A,B) +#define AS_EXPR(X) + +#endif + +#endif + -- cgit v1.2.3