1 /* 7.2 Diagnostics <assert.h>
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
7 #include <_PDCLIB_aux.h>
8 #include <_PDCLIB_config.h>
11 Defines a macro assert() that, depending on the value of the preprocessor
13 * evaluate to a void expression if NDEBUG is set OR the parameter expression
15 * print an error message and terminates the program if NDEBUG is not set AND
16 the parameter expression evaluates to false.
17 The error message contains the parameter expression, name of the source file
18 (__FILE__), line number (__LINE__), and (from C99 onward) name of the function
20 The header can be included MULTIPLE times, and redefines the macro depending
21 on the current setting of NDEBUG.
24 _PDCLIB_BEGIN_EXTERN_C
26 #ifndef _PDCLIB_ASSERT_H
27 #define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H
29 /* Functions _NOT_ tagged noreturn as this hampers debugging */
30 void _PDCLIB_assert99( char const * const, char const * const, char const * const );
31 void _PDCLIB_assert89( char const * const );
33 #if _PDCLIB_C_VERSION >= 2011
34 #define static_assert _Static_assert
36 #define static_assert( e, m )
41 /* If NDEBUG is set, assert() is a null operation. */
45 #define assert( ignore ) ( (void) 0 )
46 #elif _PDCLIB_C_MIN(99)
47 #define assert(expression) \
48 do { if(!(expression)) { \
49 _PDCLIB_assert99("Assertion failed: " _PDCLIB_symbol2string(expression)\
50 ", function ", __func__, \
52 ", line " _PDCLIB_symbol2string( __LINE__ ) \
54 _PDCLIB_UNREACHABLE; \
59 #define assert(expression) \
60 do { if(!(expression)) { \
61 _PDCLIB_assert89("Assertion failed: " _PDCLIB_symbol2string(expression)\
63 ", line " _PDCLIB_symbol2string( __LINE__ ) \
65 _PDCLIB_UNREACHABLE; \