]> pd.if.org Git - pdclib.old/blob - includes/assert.h
Modify various POSIX platform files so you can build on top of glibc for testing
[pdclib.old] / 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 ) do { \
24         if(!(expression)) { _PDCLIB_UNREACHABLE; } \
25     } while(0)
26
27 #elif _PDCLIB_C_MIN(99)
28 #define assert(expression) \
29     do { if(!(expression)) { \
30         _PDCLIB_assert99("Assertion failed: " _PDCLIB_symbol2string(expression)\
31                          ", function ", __func__, \
32                          ", file " __FILE__ \
33                          ", line " _PDCLIB_symbol2string( __LINE__ ) \
34                          "." _PDCLIB_endl ); \
35         _PDCLIB_UNREACHABLE; \
36       } \
37     } while(0)
38     
39 #else
40 #define assert(expression) \
41     do { if(!(expression)) { \
42         _PDCLIB_assert89("Assertion failed: " _PDCLIB_symbol2string(expression)\
43                          ", file " __FILE__ \
44                          ", line " _PDCLIB_symbol2string( __LINE__ ) \
45                          "." _PDCLIB_endl ); \
46         _PDCLIB_UNREACHABLE; \
47       } \
48     } while(0)
49 #endif
50
51 _PDCLIB_END_EXTERN_C
52 #endif
53