Re: taking stdbool.h into use

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: 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-26 20:53:56
Message-ID: CAB7nPqQ0mok+6VkJ06xdB74pgqbuAOnwkHvmBWQWU58bsSPOVg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 26, 2017 at 10:51 AM, Alvaro Herrera
<alvherre(at)alvh(dot)no-ip(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-10-26 20:56:33 Re: proposal: custom autovacuum entries
Previous Message Tom Lane 2017-10-26 20:47:35 Re: proposal: custom autovacuum entries