Re: taking stdbool.h into use

Michael Paquier <michael.paquier@gmail.com>

From: Michael Paquier <michael.paquier@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, Thomas Munro <thomas.munro@enterprisedb.com>
Date: 2017-10-26T20:53:56Z
Lists: pgsql-hackers
On Thu, Oct 26, 2017 at 10:51 AM, Alvaro Herrera
<alvherre@alvh.no-ip.org> wrote:
> I gave this a quick run, to see if my compiler would complain for things
> like this:
>
>    bool        isprimary = flags & INDEX_CREATE_IS_PRIMARY;
>
> (taken from the first patch at
> https://postgr.es/m/20171023161503.ohkybquxrlech7d7@alvherre.pgsql )
>
> which is assigning a value other than 1/0 to a bool variable without an
> explicit cast.  I thought it would provoke a warning, but it does not.
> Is that expected?  Is my compiler too old/new?

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;
-- 
Michael


Commits

  1. Use stdbool.h if suitable

  2. Add configure tests for stdbool.h and sizeof bool

  3. Remove useless use of bit-masking macros

  4. Change various Gin*Is* macros to return 0/1.

  5. Fix several possibly non-portable gaffs in record_image_ops.