X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=includes%2Fassert.h;fp=includes%2Fassert.h;h=e4363f510f42ad4768d35ed28cd523452da61fa8;hb=1e221deb9ee725a14b3656f94e2763f8faeb18dc;hp=0000000000000000000000000000000000000000;hpb=9712362f98b90c1a2aeec9fd877b0b872b6378c7;p=pdclib diff --git a/includes/assert.h b/includes/assert.h new file mode 100644 index 0000000..e4363f5 --- /dev/null +++ b/includes/assert.h @@ -0,0 +1,38 @@ +// ---------------------------------------------------------------------------- +// $Id$ +// ---------------------------------------------------------------------------- +// Public Domain C Library - http://pdclib.sourceforge.net +// This code is Public Domain. Use, modify, and redistribute at will. +// ---------------------------------------------------------------------------- +// Provides the debug macro assert(). +// ---------------------------------------------------------------------------- + +#ifndef __ASSERT_H +#define __ASSERT_H __ASSERT_H + +// ---------------------------------------------------------------------------- +// AUXILIARY + +// Helper function doing the print to stderr and call to abort(). +void __assert( char const * const expression, // the tested expression + char const * const file, // name of source file + char const * const function, // name of function + int const line ); // number of source file line + +// ---------------------------------------------------------------------------- +// DEFINES + +// TODO: is given as (void) 0, which might give a "C style +// cast" warning under C++. Find a void expression that does not give warnings. + +// TODO: Check the macro for if-compatibility. + +#undef assert +#if defined NDEBUG +#define assert( x ) +#else +#define assert( x ) ( x ) ? \ + : __assert( #x, __FILE__, __func__, __LINE__ ) +#endif + +#endif // __ASSERT_H