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 (<[EMAIL PROTECTED]>)
"No necesitamos banderas
 No reconocemos fronteras"                  (Jorge González)

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply via email to