Re: Memo on coding practices: strcmp() does not yield bool - Mailing list pgsql-hackers

From eisentrp@csis.gvsu.edu
Subject Re: Memo on coding practices: strcmp() does not yield bool
Date
Msg-id Pine.LNX.4.21.0007070740300.12287-100000@eos05.csis.gvsu.edu
Whole thread Raw
In response to Memo on coding practices: strcmp() does not yield bool  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: Philip Warner
Date:
Subject: Re: Re: pg_dump and LOs (another proposal)
Next
From: Thomas Lockhart
Date:
Subject: Re: DateStyle (was Re: Per-database/schema settings)