Re: GinPageIs* don't actually return a boolean - Mailing list pgsql-hackers

From Tom Lane
Subject Re: GinPageIs* don't actually return a boolean
Date
Msg-id 29927.1455294584@sss.pgh.pa.us
Whole thread Raw
In response to Re: GinPageIs* don't actually return a boolean  (Teodor Sigaev <teodor@sigaev.ru>)
Responses Re: GinPageIs* don't actually return a boolean
List 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 by date:

Previous
From: Christian Ullrich
Date:
Subject: Crash with old Windows on new CPU
Next
From: Andres Freund
Date:
Subject: Re: GinPageIs* don't actually return a boolean