X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=includes%2Fassert.h;h=cb5c47e4bd2875ba8e1874c96c6e6b7c951d0562;hb=3862b03514c94f37966f61693619e6483ead6045;hp=7874167258675dcb713b9e2f69328db9f2e2b4ad;hpb=97dd2fddbdb56005b16a1b0aa19ed15cd77269fc;p=pdclib.old diff --git a/includes/assert.h b/includes/assert.h index 7874167..cb5c47e 100644 --- a/includes/assert.h +++ b/includes/assert.h @@ -12,6 +12,7 @@ #include <_PDCLIB_config.h> _PDCLIB_BEGIN_EXTERN_C +/* Functions _NOT_ tagged noreturn as this hampers debugging */ void _PDCLIB_assert99( char const * const, char const * const, char const * const ); void _PDCLIB_assert89( char const * const ); @@ -19,24 +20,31 @@ void _PDCLIB_assert89( char const * const ); #undef assert #ifdef NDEBUG -#define assert( ignore ) ( (void) 0 ) -#elif _PDCLIB_C_VERSION >= 99 +#define assert( ignore ) do { \ + if(!(expression)) { _PDCLIB_UNREACHABLE; } \ + } while(0) + +#elif _PDCLIB_C_MIN(99) #define assert(expression) \ - do { if(!(expression)) \ - _PDCLIB_assert99("Assertion failed: " #expression \ + do { if(!(expression)) { \ + _PDCLIB_assert99("Assertion failed: " _PDCLIB_symbol2string(expression)\ ", function ", __func__, \ ", file " __FILE__ \ ", line " _PDCLIB_symbol2string( __LINE__ ) \ "." _PDCLIB_endl ); \ + _PDCLIB_UNREACHABLE; \ + } \ } while(0) + #else #define assert(expression) \ - do { \ - if(!(expression)) \ - _PDCLIB_assert89( "Assertion failed: " #expression \ - ", file " __FILE__ \ - ", line " _PDCLIB_symbol2string( __LINE__ ) \ - "." _PDCLIB_endl ); \ + do { if(!(expression)) { \ + _PDCLIB_assert89("Assertion failed: " _PDCLIB_symbol2string(expression)\ + ", file " __FILE__ \ + ", line " _PDCLIB_symbol2string( __LINE__ ) \ + "." _PDCLIB_endl ); \ + _PDCLIB_UNREACHABLE; \ + } \ } while(0) #endif