From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Ed Loehr <eloehr(at)austin(dot)rr(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Memo on coding practices: strcmp() does not yield bool |
Date: | 2000-07-07 17:05:18 |
Message-ID: | 10864.962989518@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Ed Loehr <eloehr(at)austin(dot)rr(dot)com> writes:
> I see your examples demonstrate the danger of inappropriate or
> inattentive type conversion (e.g., splicing an int into a char), but I'm
> missing the danger you see, beyond a style offense, of "if (strcmp(foo,
> bar))"?
"if (strcmp(foo, bar))" is portable, no doubt about it. My point is
that the idiom encourages one to think of strcmp() as yielding bool,
which leads directly to the sort of thinko I exhibited. It's a
slippery-slope argument, basically.
I had always disliked the idiom on stylistic grounds, but I never quite
had a rational reason why. Now I do: it's a type violation. If C had
a distinction between int and bool then you'd not be allowed to write
this. As an old Pascal programmer I prefer to think of the two types
as distinct...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2000-07-07 17:12:59 | Re: Re: [SQL] MAX() of 0 records. |
Previous Message | Robert B. Easter | 2000-07-07 16:53:27 | Re: Re: [HACKERS] Re: [SQL] MAX() of 0 records. |