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

From: eisentrp(at)csis(dot)gvsu(dot)edu
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Memo on coding practices: strcmp() does not yield bool
Date: 2000-07-07 11:43:51
Message-ID: Pine.LNX.4.21.0007070740300.12287-100000@eos05.csis.gvsu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message eisentrp 2000-07-07 11:54:33 Re: [HACKERS] PostgreSQL & the BSD License
Previous Message Jan Wieck 2000-07-07 11:30:15 Re: update on TOAST status'