Skip site navigation (1) Skip section navigation (2)

Re: sparse (static analyzer) report

From: Tommi Mäkitalo <t(dot)maekitalo(at)epgmbh(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: sparse (static analyzer) report
Date: 2005-01-15 23:22:07
Message-ID: 200501160022.07381.t.maekitalo@epgmbh.de (view raw or flat)
Thread:
Lists: pgsql-hackers
Am Samstag, 15. Januar 2005 21:38 schrieb Bruno Wolff III:
> On Sat, Jan 15, 2005 at 10:44:48 -0500,
>
>   Greg Stark <gsstark(at)mit(dot)edu> wrote:
> > What I miss most in both C and Java is the lispish ability to write
> > expressions like:
> >
> >  foo = bar() || baz() || qux();
>
> Are you sure that C doesn't guarenty short circuit evaluation?
> I don't have my C reference handy, but my memory is that evaluation
> will stop after the first function call that returns true in the
> above expression.
>
C do guaranty short circuit evaluation.

You can also write:

(foo = bar()) || (foo = baz()) || (foo = qux())

this is a valid shortcut, where bar(), baz() and qux() are not evaluated 
twice, like in the if-cascade. But it is a ugly style every stylechecker 
should have no problems complaining about. Even a compiler would warn about 
'=' and '=='-confusion. But you can fix it:

(foo = bar()) != NULL || (foo = baz()) != NULL || foo = qux()) != NULL;

It's short, but not quite that readable.


Tommi

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2005-01-15 23:46:47
Subject: Re: Encodings and docs
Previous:From: Bruce MomjianDate: 2005-01-15 22:47:27
Subject: Encodings and docs

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group