]> pd.if.org Git - pdclib/blob - includes/assert.h
Initial load with header templates and some first declarations.
[pdclib] / includes / assert.h
1 // ----------------------------------------------------------------------------
2 // $Id$
3 // ----------------------------------------------------------------------------
4 // Public Domain C Library - http://pdclib.sourceforge.net
5 // This code is Public Domain. Use, modify, and redistribute at will.
6 // ----------------------------------------------------------------------------
7 // Provides the debug macro assert().
8 // ----------------------------------------------------------------------------
9
10 #ifndef __ASSERT_H
11 #define __ASSERT_H __ASSERT_H
12
13 // ----------------------------------------------------------------------------
14 // AUXILIARY
15
16 // Helper function doing the print to stderr and call to abort().
17 void __assert( char const * const expression, // the tested expression
18                char const * const file,       // name of source file
19                char const * const function,   // name of function
20                int const line );              // number of source file line
21
22 // ----------------------------------------------------------------------------
23 // DEFINES
24
25 // TODO: <void expression> is given as (void) 0, which might give a "C style
26 // cast" warning under C++. Find a void expression that does not give warnings.
27
28 // TODO: Check the macro for if-compatibility.
29
30 #undef assert
31 #if defined NDEBUG
32 #define assert( x ) <void expression>
33 #else
34 #define assert( x ) ( x ) ? <void expression> \
35                           :  __assert( #x, __FILE__, __func__, __LINE__ )
36 #endif
37
38 #endif // __ASSERT_H