Re: GinPageIs* don't actually return a boolean

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: GinPageIs* don't actually return a boolean
Дата
Msg-id 29927.1455294584@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: GinPageIs* don't actually return a boolean  (Teodor Sigaev <teodor@sigaev.ru>)
Ответы Re: GinPageIs* don't actually return a boolean  (Andres Freund <andres@anarazel.de>)
Список pgsql-hackers
Teodor Sigaev <teodor@sigaev.ru> writes:
> One more option for patch:
> #define GinPageIsLeaf(page)    ((bool)(GinPageGetOpaque(page)->flags & GIN_LEAF))

I think that's a seriously bad coding pattern to adopt, because it would
work for some people but not others if the flag bit is to the left of the
rightmost byte.  We should standardize on the "((var & FLAG) != 0)"
pattern, which works reliably in all cases.

The pattern "(!!(var & FLAG))" would work too, but I dislike it because
it is not "say what you mean" but more of a cute coding trick to save a
keystroke or two.  People who aren't longtime C coders would have to stop
and think about what it does.

(I'd expect reasonable compilers to generate pretty much the same code
in any of these cases, so that aspect of it shouldn't be an issue.)
        regards, tom lane



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

Предыдущее
От: Christian Ullrich
Дата:
Сообщение: Crash with old Windows on new CPU
Следующее
От: Andres Freund
Дата:
Сообщение: Re: GinPageIs* don't actually return a boolean