Re: [HACKERS] taking stdbool.h into use - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] taking stdbool.h into use
Date
Msg-id 23240.1509064904@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] taking stdbool.h into use  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Responses Re: [HACKERS] taking stdbool.h into use
List pgsql-hackers
Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> Michael Paquier wrote:
>> It seems to me that this proves the point of the proposed patch. You
>> had better use a zero-equality comparison for such bitwise operation,
>> and so you ought to do that:
>> bool        isprimary = (flags & INDEX_CREATE_IS_PRIMARY) != 0;

> Right, exactly.  But my point is that with the whole patch series
> applied I didn't get any warnings.

While warnings for this would be lovely, I don't see how we can expect to
get any.  This is perfectly correct C code no matter whether isprimary
is C99 bool or is typedef'd to char ... you just end up with different
values of isprimary, should the RHS produce something other than 1/0.
The compiler has no way to know that assigning, say, 4 in the char
variable case is not quite your intent.  Maybe you could hope for a
warning if the bit value were far enough left to actually not fit into
"char", but otherwise there's nothing wrong.
        regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: [HACKERS] FieldSelect/FieldStore dependencies, take 2
Next
From: Amit Langote
Date:
Subject: Re: [HACKERS] path toward faster partition pruning