[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: abort or verify?

From: Benjamin Pflugmann <benjamin-svn-dev_at_pflugmann.de>
Date: 2004-11-11 17:00:58 CET

On Wed 2004-11-10 at 16:44:53 -0700, Justin Erenkrantz wrote:
> --On Thursday, November 11, 2004 1:19 AM +0100 "Branko ?ibej" wrote:
> >>I'm not sure how you'd have it defined to be the same. The expansion
> >>of assert() is different on each platform, IIRC.
> >
> >Yes, but the following would almost do the trick:
> >
> > #define verify(x) do { assert(x); if (!(x)) abort(); } while(1)
> But, you'd incur a double penalty when assert is defined. That's badness,
> IMHO. -- justin

That could be solved by changing the order:

 #define VERIFY(x) do { if(!(x)) { assert(x); abort(); } while(0)

which only invokes the double penalty in the case where we are going
to assert/abort anyhow.

Another problem with either method, which already got mentioned, is
multiple evaluation of (x). And while it's possible to avoid that by
using a temp variable, I think using "#ifdef NDEBUG" is better
(because assert() could be an define that tries to make use of the
expression itself, not only its boolean result).

On Thu 2004-11-11 at 10:05:13 -0000, Ben Sewell wrote:
> >
> > #define verify(x) do { assert(x); if (!(x)) abort(); } while(1)
> Maybe I'm missing something, but isn't that "while(0)"?

Jupp. We don't want to loop forever when (x == true), which is the
common case in bug-free code.



To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Nov 11 17:01:14 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.