]> pd.if.org Git - pdclib/blob - includes/assert.h
Initial pass at a port to win32
[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 /* Functions _NOT_ tagged noreturn as this hampers debugging */
16 void _PDCLIB_assert99( char const * const, char const * const, char const * const );
17 void _PDCLIB_assert89( char const * const );
18
19 /* If NDEBUG is set, assert() is a null operation. */
20 #undef assert
21
22 #ifdef NDEBUG
23 #define assert( ignore ) ( (void) 0 )
24 #elif _PDCLIB_C_MIN(99)
25 #define assert(expression) \
26     do { if(!(expression)) { \
27         _PDCLIB_assert99("Assertion failed: " _PDCLIB_symbol2string(expression)\
28                          ", function ", __func__, \
29                          ", file " __FILE__ \
30                          ", line " _PDCLIB_symbol2string( __LINE__ ) \
31                          "." _PDCLIB_endl ); \
32       } \
33     } while(0)
34 #else
35 #define assert(expression) \
36     do { if(!(expression)) { \
37         _PDCLIB_assert89("Assertion failed: " _PDCLIB_symbol2string(expression)\
38                          ", file " __FILE__ \
39                          ", line " _PDCLIB_symbol2string( __LINE__ ) \
40                          "." _PDCLIB_endl ); \
41       } \
42     } while(0)
43 #endif
44
45 _PDCLIB_END_EXTERN_C
46 #endif
47