Assert

This page doesn't reference the following text from Wikipedia. In the future, please rectify this situation and either rewrite the page without the Wikipedia, or reference it.

assert.h is a header file in the standard library of the C programming language that defines the C preprocessor macro assert(). The macro implements an assertion, which can be used to verify assumptions made by the program.

The assert() macro inserts diagnostics into programs. When executed, if the expression is false (that is, compares equal to 0), assert() writes information about the call that failed on stderr and then calls abort(). The information it writes to stderr includes:

* the text of expression that evaluated to 0
* the source filename (the predefined macro FILE)
* the source line number (the predefined macro LINE)

Programmers can eliminate the assertions without changing the source code: if the macro NDEBUG is defined before the inclusion of <assert.h>, the assert() macro is defined simply as:

#define assert(ignore)((void) 0)

and therefore has no effect on the program, not even evaluating its argument.
Retrieved from "http://en.wikipedia.org/wiki/Assert.h"

Following code pulled from the pdclib: http://sourceforge.net/projects/pdclib

<clib/assert.h>

#ifndef _DCLIB_AUX_H
    #define _DCLIB_AUX_H _DCLIB_AUX_H
    #include <_DCLIB_aux.h>
#endif

#ifndef _DCLIB_CONFIG_H
    #define _DCLIB_CONFIG_H _DCLIB_CONFIG_H
    #include <_DCLIB_config.h>
#endif

#ifndef _DCLIB_ASSERT_H
    #define _DCLIB_ASSERT_H _DCLIB_ASSERT_H
    #if _DCLIB_C_VERSION == 99
        void _DCLIB_assert( char const * const, char const * const, char const * const );
    #else
        void _DCLIB_assert( char const * const );
    #endif
#endif

/* If NDEBUG is set, assert() is a null operation. */
#undef assert

#ifdef NDEBUG
    #define assert( ignore ) ( (void) 0 )
#else
#if _DCLIB_C_VERSION == 99
    #define assert( expression ) ( ( expression ) ? (void) 0 \
        : _DCLIB_assert( "Assertion failed: " #expression \
                          ", function ", __func__, \
              ", file " __FILE__ \
              ", line " _DCLIB_symbol2string( __LINE__ ) \
              "." _DCLIB_endl ) )
#else
    #define assert( expression ) ( ( expression ) ? (void) 0 \
    : _PCLIB_assert( "Assertion failed: " #expression \
                      ", file " __FILE__ \
                      ", line " _DCLIB_symbol2string( __LINE__ ) \
                      "." _DCLIB_endl ) )
#endif
#endif
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License