bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

assert.h replacement (was: Re: __func__)


From: Simon Josefsson
Subject: assert.h replacement (was: Re: __func__)
Date: Tue, 04 Mar 2008 15:52:07 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux)

Eric Blake <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]