Re: Memo on coding practices: strcmp() does not yield bool
В списке pgsql-hackers по дате отправления:
| От | Tom Lane |
|---|---|
| Тема | Re: Memo on coding practices: strcmp() does not yield bool |
| Дата | |
| Msg-id | 10864.962989518@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: Memo on coding practices: strcmp() does not yield bool (Ed Loehr <eloehr@austin.rr.com>) |
| Список | pgsql-hackers |
Ed Loehr <eloehr@austin.rr.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
В списке pgsql-hackers по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера