Simon Josefsson <simon <at> josefsson.org> writes: > Ah, ok, I thought you talked about the existing 'assert' module in > gnulib, which looks unrelated to what you are proposing.
I'm actually thinking that that it would be better to make the existing assert module serve the two orthogonal purposes (provide ./configure --disable-assert, and make assert() guarantee that __func__ is included in the output), rather than creating a new module. And note that while it is easy to test for __func__ support, there are platforms with __func__ support but a broken assert (such as cygwin 1.5.x), so you would need an AC_RUN_IFELSE test to detect it. > > 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__); \ Not quite. Using if(){} will break if assert occurs as the sole statement inside another if-else pair - use while(){} or ?: instead. You also need to use #e to get the stringized text of the expression into the output, and while program_name is nice, it is not required (using it would drag in a dependency on program_name). POSIX states that "The information written about the call that failed shall include the text of the argument, the name of the source file, the source file line number, and the name of the enclosing function;". But I think you are right that we can avoid the need for an rpl_assert function. > > But are there any platforms that lack an assert.h? Not to my knowledge - at any rate, several gnulib modules assume its presence unconditionally. -- Eric Blake