C Programming/Code library
Jump to navigation
Jump to search
This page or section is an undeveloped draft or outline. You can help to develop the work, or you can ask for assistance in the project room. |
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)
#else
void _Assertfail(char *, char *, int, char *);
#define assert(_Test) ((_Test)?((void)0):_Assertfail(#_Test,__FILE__,__LINE__,__func__))
#endif
/* END OF FILE */
/* xassertfail.c -- _Assertfail function */
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
void
_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);
abort();
}
/* END OF FILE */