Re: sparse (static analyzer) report - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: sparse (static analyzer) report
Date
Msg-id 20050115134137.GA25902@dcc.uchile.cl
Whole thread Raw
In response to Re: sparse (static analyzer) report  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
On Sat, Jan 15, 2005 at 08:31:42AM -0500, Andrew Dunstan wrote:

> Tom Lane wrote:

> >Something that I don't have a real strong feeling about is
> >    if (ptr != NULL)
> >versus
> >    if (ptr)
> >I've been known to write both.  Can anyone mount a good readability
> >argument for one over the other?

I assume people don't like the PointerIsValid() macro defined in c.h?

Just for consistency we could use that everywhere or get rid of it ...
but then, maybe it is used by external code so we shouldn't do the
latter.

> >How about the inverse case,
> >    if (ptr == NULL)
> >versus
> >    if (!ptr)
> >Applying a boolean ! to a pointer seems a bit shaky to me, though
> >it's certainly a common locution.
> 
> If we allow "if (ptr)" then allowing the inverse to be "if (! ptr)" 
> seems logical enough. As you say, it's a very common idiom, and allowing 
> one without the other would be rather non-orthogonal.

I'd rather have legibility over orthogonality on this issue.  I prefer
ptr == NULL myself, though not too strongly.

-- 
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"No necesitamos banderasNo reconocemos fronteras"                  (Jorge Gonz�lez)


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: sparse (static analyzer) report
Next
From: Greg Stark
Date:
Subject: Re: sparse (static analyzer) report