[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: Branko Čibej <brane_at_xbc.nu>
Date: 2004-11-11 21:28:53 CET

Jim Correia wrote:

> On Nov 10, 2004, at 7:19 PM, Branko Čibej wrote:
>
>> Yes, but the following would almost do the trick:
>>
>> #define verify(x) do { assert(x); if (!(x)) abort(); } while(1)
>
>
> That will cause the macro argument to get evaluated twice if assert is
> defined. This is bad news if it was an expression or function call.
>
> You'd want to do something like this (written in my email client and
> untested)
>
> #define
> verify_noerr(expression) \
>
> do \
>
> { \
> int evalOnce =
> (expression); \
>
> assert(evalOnce); \

That unfortunately won't do what you want, because assert is always a
macro that somehow prints out the expression that failed. So the best
way is probably this:

#ifndef NDEBUG
#define SVN_VERIFY(x) assert(x)
#else
#define SVN_VERIFY(x) if ((x)); else abort()
#endif

-- Brane

---------------------------------------------------------------------
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:28:52 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.