Re: Memo on coding practices: strcmp() does not yield bool

Поиск
Список
Период
Сортировка
От eisentrp@csis.gvsu.edu
Тема Re: Memo on coding practices: strcmp() does not yield bool
Дата
Msg-id Pine.LNX.4.21.0007070740300.12287-100000@eos05.csis.gvsu.edu
обсуждение исходный текст
Ответ на Memo on coding practices: strcmp() does not yield bool  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Thu, 6 Jul 2000, Tom Lane wrote:

> I've occasionally griped that I do not like the coding practice of
> writing
>     if (strcmp(foo, bar))
> to mean
>     if (strcmp(foo, bar) != 0)

Why not define a macro to avoid the urge to take shortcuts like that in
the future?

#define streq(a,b) (strcmp((a), (b))==0)

This is guaranteed to yield 1 or 0, and it's very readable.


-- 
Peter Eisentraut                  Sernanders vaeg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Philip Warner
Дата:
Сообщение: Re: Re: pg_dump and LOs (another proposal)
Следующее
От: Thomas Lockhart
Дата:
Сообщение: Re: DateStyle (was Re: Per-database/schema settings)