From f02540ff10b332b8ef5ad9e89ded894e39d68bec Mon Sep 17 00:00:00 2001 From: kleink Date: Tue, 19 Dec 2000 14:32:59 +0000 Subject: C99: Print the name of the function enclosing the assertion, if possible. --- include/assert.h | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'include/assert.h') diff --git a/include/assert.h b/include/assert.h index 125b21a034b..f8c6e7bd2d6 100644 --- a/include/assert.h +++ b/include/assert.h @@ -1,4 +1,4 @@ -/* $NetBSD: assert.h,v 1.9 2000/08/07 16:21:32 kleink Exp $ */ +/* $NetBSD: assert.h,v 1.10 2000/12/19 14:32:59 kleink Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -59,9 +59,13 @@ #else /* !NDEBUG */ # define _assert(e) assert(e) # if __STDC__ -# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, #e)) +# define assert(e) \ + ((e) ? (void)0 : __assert13(__FILE__, __LINE__, \ + __assert_function__, #e)) # else /* PCC */ -# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, "e")) +# define assert(e) \ + ((e) ? (void)0 : __assert13(__FILE__, __LINE__, \ + __assert_function__, "e")) # endif /* !__STDC__ */ #endif /* NDEBUG */ @@ -74,16 +78,30 @@ # endif /* lint */ #else /* _DIAGNOSTIC */ # if __STDC__ -# define _DIAGASSERT(e) ((e) ? (void)0 : __diagassert(__FILE__, __LINE__, #e)) +# define _DIAGASSERT(e) \ + ((e) ? (void)0 : __diagassert13(__FILE__, __LINE__, \ + __assert_function__, #e)) # else /* !__STDC__ */ -# define _DIAGASSERT(e) ((e) ? (void)0 : __diagassert(__FILE__, __LINE__, "e")) +# define _DIAGASSERT(e) \ + ((e) ? (void)0 : __diagassert13(__FILE__, __LINE__, \ + __assert_function__, "e")) # endif #endif /* _DIAGNOSTIC */ #include +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#define __assert_function__ __func__ +#elif __GNUC_PREREQ__(2, 6) +#define __assert_function__ __PRETTY_FUNCTION__ +#else +#define __assert_function__ ((const void *)0) +#endif + __BEGIN_DECLS void __assert __P((const char *, int, const char *)); +void __assert13 __P((const char *, int, const char *, const char *)); void __diagassert __P((const char *, int, const char *)); +void __diagassert13 __P((const char *, int, const char *, const char *)); __END_DECLS -- cgit