C Programming/Code library

< C Programming
Previous: GObject Index Next: Reference Tables

The following is an implementation of the Standard C99 version of <assert.h>:

 /* assert.h header */
 #undef assert
 #ifdef NDEBUG
 #define assert(_Ignore) ((void)0)
 void _Assertfail(char *, char *, int, char *);
 #define assert(_Test) ((_Test)?((void)0):_Assertfail(#_Test,__FILE__,__LINE__,__func__))
 /* END OF FILE */
 /* xassertfail.c -- _Assertfail function */
 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>
 _Assertfail(char *test, char *filename, int line_number, char *function_name)
    fprintf(stderr, "Assertion failed: %s, function %s, file %s, line %d.",
            test, function_name, filename, line_number);
 /* END OF FILE */
Previous: Mixing languages Index Next: Reference Tables