Re: strange case of "if ((a & b))"

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Justin Pryzby <pryzby@telsasoft.com>, pgsql-hackers@lists.postgresql.org
Date: 2021-05-10T06:27:13Z
Lists: pgsql-hackers
On Wed, Apr 28, 2021 at 02:40:09PM -0400, Tom Lane wrote:
> Justin Pryzby <pryzby@telsasoft.com> writes:
>> These look strange to me - the inner parens don't do anything.
>> I wouldn't write it with 2x parens for the same reason I wouldn't write it with
>> 8x parens.
> 
> Agreed, but shouldn't we just drop the excess parens rather than
> doubling down on useless notation?

Using a notation like ((a & b) != 0) to enforce a boolean check after
the bitwise operation is the usual notation I've preferred, FWIW.  Do
you mean something different here?
--
Michael

Commits

  1. Clean up more code using "(expr) ? true : false"

  2. Clean up some code using "(expr) ? true : false"