3 /* 7.2 Diagnostics <assert.h>
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
9 #include <_PDCLIB_aux.h>
10 #include <_PDCLIB_config.h>
13 Defines a macro assert() that, depending on the value of the preprocessor
15 * evaluate to a void expression if NDEBUG is set OR the parameter expression
17 * print an error message and terminates the program if NDEBUG is not set AND
18 the parameter expression evaluates to false.
19 The error message contains the parameter expression, name of the source file
20 (__FILE__), line number (__LINE__), and (from C99 onward) name of the function
22 The header can be included MULTIPLE times, and redefines the macro depending
23 on the current setting of NDEBUG.
26 _PDCLIB_BEGIN_EXTERN_C
28 #ifndef _PDCLIB_ASSERT_H
29 #define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H
31 /* Functions _NOT_ tagged noreturn as this hampers debugging */
32 void _PDCLIB_assert99( char const * const, char const * const, char const * const );
33 void _PDCLIB_assert89( char const * const );
37 /* If NDEBUG is set, assert() is a null operation. */
41 #define assert( ignore ) do { \
42 if(!(expression)) { _PDCLIB_UNREACHABLE; } \
45 #elif _PDCLIB_C_MIN(99)
46 #define assert(expression) \
47 do { if(!(expression)) { \
48 _PDCLIB_assert99("Assertion failed: " _PDCLIB_symbol2string(expression)\
49 ", function ", __func__, \
51 ", line " _PDCLIB_symbol2string( __LINE__ ) \
53 _PDCLIB_UNREACHABLE; \
58 #define assert(expression) \
59 do { if(!(expression)) { \
60 _PDCLIB_assert89("Assertion failed: " _PDCLIB_symbol2string(expression)\
62 ", line " _PDCLIB_symbol2string( __LINE__ ) \
64 _PDCLIB_UNREACHABLE; \