/* Diagnostics <assert.h>12This file is part of the Public Domain C Library (PDCLib).3Permission is granted to use, modify, and / or redistribute at will.4*/56#include "_PDCLIB_aux.h"7#include "_PDCLIB_config.h"89/*10Defines a macro assert() that, depending on the value of the preprocessor11symbol NDEBUG, does12* evaluate to a void expression if NDEBUG is set OR the parameter expression13evaluates to true;14* print an error message and terminates the program if NDEBUG is not set AND15the parameter expression evaluates to false.16The error message contains the parameter expression, name of the source file17(__FILE__), line number (__LINE__), and (from C99 onward) name of the function18(__func__).19The header can be included MULTIPLE times, and redefines the macro depending20on the current setting of NDEBUG.21*/2223#ifndef _PDCLIB_ASSERT_H24#define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H2526#ifdef __cplusplus27extern "C" {28#endif2930/* Functions _NOT_ tagged noreturn as this hampers debugging */31void _PDCLIB_assert99( char const * const, char const * const, char const * const );32void _PDCLIB_assert89( char const * const );3334#ifdef __cplusplus35}36#endif3738#if _PDCLIB_C_VERSION >= 201139#define static_assert _Static_assert40#else41#define static_assert( e, m )42#endif4344#endif4546/* If NDEBUG is set, assert() is a null operation. */47#undef assert4849#ifdef NDEBUG50#define assert( ignore ) ( (void) 0 )51#elif _PDCLIB_C_MIN(99)52#define assert(expression) \53do { if(!(expression)) { \54_PDCLIB_assert99("Assertion failed: " _PDCLIB_symbol2string(expression)\55", function ", __func__, \56", file " __FILE__ \57", line " _PDCLIB_symbol2string( __LINE__ ) \58"." _PDCLIB_endl ); \59_PDCLIB_UNREACHABLE; \60} \61} while(0)6263#else64#define assert(expression) \65do { if(!(expression)) { \66_PDCLIB_assert89("Assertion failed: " _PDCLIB_symbol2string(expression)\67", file " __FILE__ \68", line " _PDCLIB_symbol2string( __LINE__ ) \69"." _PDCLIB_endl ); \70_PDCLIB_UNREACHABLE; \71} \72} while(0)73#endif747576