From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> |
Subject: | Re: taking stdbool.h into use |
Date: | 2017-10-27 00:41:44 |
Message-ID: | 23240.1509064904@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Langote | 2017-10-27 01:17:17 | Re: path toward faster partition pruning |
Previous Message | Tom Lane | 2017-10-27 00:29:06 | FieldSelect/FieldStore dependencies, take 2 |