]> pd.if.org Git - pdclib/blob - includes/assert.h
* Change the style of inclusion of the internal/ headers. Modern preprocessors
[pdclib] / includes / assert.h
1 /* $Id$ */
2
3 /* 7.2 Diagnostics <assert.h>
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #ifndef _PDCLIB_ASSERT_H
10 #define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H
11 #include <_PDCLIB_aux.h>
12 #include <_PDCLIB_config.h>
13 _PDCLIB_BEGIN_EXTERN_C
14
15 void _PDCLIB_assert99( char const * const, char const * const, char const * const );
16 void _PDCLIB_assert89( char const * const );
17
18 /* If NDEBUG is set, assert() is a null operation. */
19 #undef assert
20
21 #ifdef NDEBUG
22 #define assert( ignore ) ( (void) 0 )
23 #elif _PDCLIB_C_VERSION >= 99
24 #define assert(expression) \
25     do { if(!(expression)) \
26         _PDCLIB_assert99("Assertion failed: " #expression \
27                          ", function ", __func__, \
28                          ", file " __FILE__ \
29                          ", line " _PDCLIB_symbol2string( __LINE__ ) \
30                          "." _PDCLIB_endl ); \
31     } while(0)
32 #else
33 #define assert(expression) \
34     do { \
35         if(!(expression)) \
36             _PDCLIB_assert89( "Assertion failed: " #expression \
37                           ", file " __FILE__ \
38                           ", line " _PDCLIB_symbol2string( __LINE__ ) \
39                           "." _PDCLIB_endl ); \
40     } while(0)
41 #endif
42
43 _PDCLIB_END_EXTERN_C
44 #endif
45