[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: Peter N. Lundblad <peter_at_famlundblad.se>
Date: 2004-11-11 21:25:19 CET

On Thu, 11 Nov 2004, Benjamin Pflugmann wrote:

> On Wed 2004-11-10 at 16:44:53 -0700, Justin Erenkrantz wrote:
> > > #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.
>
I don't see why we need to do this. We have control over the build
process, so why not just ensure the NDEBUG is not defined? As Branko
pointed out, it's no problem under Windows anymore. Is there another
platform where you can't do a "release build" with NDEBUG undefined?

I think assert is good because it is a well-established idiom.

> 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).
>
Relying on side effects in an assert or verify or whatever is a bug. We
shouldn't encourage that.

Best,
//Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Nov 11 21:47:50 2004

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