medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 01321e760c4a5e25713d1aa0cfec577a12440bfe
parent 104f8181ce3830f486c9c3ad7a59bb742784482c
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Aug 16 11:56:06 +0200

Better assert macro

Diffstat:
intrinsics.h | 14+++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/intrinsics.h b/intrinsics.h @@ -1,6 +1,7 @@ #ifndef _INTRINSICS_H_ #define _INTRINSICS_H_ +#include <stdio.h> #include <stdint.h> #include "platform_backtrace.h" @@ -22,7 +23,18 @@ typedef double f64; #ifdef assert #undef assert #endif -#define assert( predicate ) { if( !( predicate ) ) { print_backtrace(); __builtin_trap(); } } + +inline void mike_assert( const bool predicate, const char * const message ) { + if( !( predicate ) ) { + puts( message ); + print_backtrace(); + __builtin_trap(); + } +} + +#define STRINGIFY_HELPER( x ) #x +#define STRINGIFY( x ) STRINGIFY_HELPER( x ) +#define assert( predicate ) mike_assert( predicate, "assertion failed at " __FILE__ " line " STRINGIFY( __LINE__ ) ": " #predicate ) #define is_power_of_2( n ) ( ( ( n ) & ( ( n ) - 1 ) ) == 0 ) #define align_power_of_2( n, alignment ) ( ( ( n ) + ( alignment ) - 1 ) & ~( ( alignment ) - 1 ) )