Mail Archives: djgpp-workers/2003/11/24/05:31:19
C99 says that assert should print function name in addition to file name
and line number. Compatibility with old versions of gcc demands some
complications (at least I think so):
Index: include/assert.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/assert.h,v
retrieving revision 1.3
diff -c -r1.3 assert.h
*** include/assert.h 7 Sep 1997 21:06:10 -0000 1.3
--- include/assert.h 24 Nov 2003 10:17:48 -0000
***************
*** 6,12 ****
#if defined(NDEBUG)
#define assert(test) ((void)0)
#else
! #define assert(test) ((void)((test)||(__dj_assert(#test,__FILE__,__LINE__),0)))
#endif
#ifndef __dj_include_assert_h_
--- 6,16 ----
#if defined(NDEBUG)
#define assert(test) ((void)0)
#else
! #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
! #define assert(test) ((void)((test)||(__dj_assert(#test,__FILE__,__LINE__,__func__),0)))
! #else
! #define assert(test) ((void)((test)||(__dj_assert(#test,__FILE__,__LINE__,NULL),0)))
! #endif
#endif
#ifndef __dj_include_assert_h_
***************
*** 16,22 ****
extern "C" {
#endif
! void __dj_assert(const char *,const char *,int) __attribute__((__noreturn__));
#ifdef __cplusplus
}
--- 20,26 ----
extern "C" {
#endif
! void __dj_assert(const char *,const char *,int, const char *) __attribute__((__noreturn__));
#ifdef __cplusplus
}
Index: src/libc/ansi/assert/assert.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/assert/assert.c,v
retrieving revision 1.1
diff -c -r1.1 assert.c
*** src/libc/ansi/assert/assert.c 29 Nov 1994 09:17:44 -0000 1.1
--- src/libc/ansi/assert/assert.c 24 Nov 2003 10:17:48 -0000
***************
*** 4,13 ****
#include <signal.h>
#include <stdlib.h>
! void __dj_assert(const char *msg, const char *file, int line)
{
! /* Assertion failed at foo.c line 45: x<y */
! fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, msg);
raise(SIGABRT);
exit(1);
}
--- 4,16 ----
#include <signal.h>
#include <stdlib.h>
! void __dj_assert(const char *msg, const char *file, int line, const char *func)
{
! /* Assertion failed at foo.c line 45, function bar: x<y */
! fprintf(stderr, "Assertion failed at %s line %d", file, line);
! if(func)
! fprintf(stderr, ", function %s", func);
! fprintf(stderr, ": %s\n", msg);
raise(SIGABRT);
exit(1);
}
--
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/
- Raw text -