bug-gnulib
[Top][All Lists]
Advanced

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

Re: [Bug-gnulib] hash.c change to use abort rather than assert


From: Bruno Haible
Subject: Re: [Bug-gnulib] hash.c change to use abort rather than assert
Date: Tue, 26 Nov 2002 15:05:41 +0100 (CET)

Paul Eggert writes:
> > I prefer to turn
> > 
> >      assert (bucket < table->bucket_limit);
> > 
> > into
> > 
> >      if (!(bucket < table->bucket_limit))
> >        abort ();
> 
> How about if we turn it into this instead:
> 
>     aver (bucket < table->bucket_limit);
>
> with the following definition for "aver":
> 
>     #ifdef NDEBUG
>     # define aver(X) ((void) 0)
>     #else
>     # define aver(X) ((X) ? (void) 0 : abort ())
>     #endif

OK but then where's the big difference versus using assert() itself?
I can see why bison doesn't want to use assert() in generated code,
because it requires a #include. But for gnulib?

you wrote:

> as the GNU Coding Standards hint that one should use `if (! x) abort
> ();' rather than `assert (x);'

I interpret the paragraph

   "In error checks that detect "impossible" conditions, just
    abort. There is usually no point in printing any message."

as meaning "Don't waste your time writing an fprintf error message,
setting an exit code etc."

But when we have an assert() macro that does all that aver() does,
plus an error message (including file and line numbers) at no cost,
why not use it?

Bruno




reply via email to

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