Eric Blake <[EMAIL PROTECTED]> writes:
> According to Simon Josefsson on 3/3/2008 9:07 AM:
> |> I like the idea. I would also like to see the assert module use it, if
> the
> |> platform's assert() lacks __func__ information as required by C99/POSIX
> 2001.
> |
> | How can that be implemented? The current assert module seems to only
> | add a --disable-assert, rather than replacing a incorrect assert
> | function.
>
> Well, it would imply a gnulib replacement <assert.h>. Unfortunately, I
> don't see any easy way to see what underlying function assert expands to
> when NDEBUG is not defined, so all I can think of is adding assert.c to
> gnulib, declaring rpl_assert(int expr, const char *file, int line, const
> char *function), and doing:
>
> #ifdef NDEBUG
> # define assert(e) ((void) 0)
> #else
> # define assert(e) ((e) ? (void) 0 \
> ~ : rpl_assert (#e, __FILE__, __LINE__, __func__))
> #endif
Ah, ok, I thought you talked about the existing 'assert' module in
gnulib, which looks unrelated to what you are proposing.
Couldn't a replacement assert.h look like:
#include <stdio.h>
#include "progname.h"
#ifdef NDEBUG
# define assert(e) ((void) 0)
#else
# define assert(e) \
if (!(e)) { \
fprintf (stderr, "%s: %s: %s: %s: Assertion failed.\n", \
program_name, __FILE__, __LINE__, __func__); \
abort(); \
}
#endif
?
But are there any platforms that lack an assert.h?
/Simon