Re: sparse (static analyzer) report

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: sparse (static analyzer) report
Дата
Msg-id 20050115134137.GA25902@dcc.uchile.cl
обсуждение исходный текст
Ответ на Re: sparse (static analyzer) report  (Andrew Dunstan <andrew@dunslane.net>)
Список 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 по дате отправления:

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: sparse (static analyzer) report
Следующее
От: Greg Stark
Дата:
Сообщение: Re: sparse (static analyzer) report