pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Smith <smithpb2250@gmail.com>
Cc: Justin Pryzby <pryzby@telsasoft.com>
Cc: Bruce Momjian <bruce@momjian.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: strange case of "if ((a & b))"
Date: Wed, 18 Aug 2021 23:08:57 -0400
Message-ID: <1673521.1629342537@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHut+Ps6Y9ZeAXfUntci0NX6tBqNu+Rj1hy8BsuqXPLrXeUvFQ@mail.gmail.com>
References: <20210428182936.GE27406@telsasoft.com>
	<2896014.1619635209@sss.pgh.pa.us>
	<20210625023110.GI29179@telsasoft.com>
	<20210818180222.GE13002@momjian.us>
	<20210818182856.GR10479@telsasoft.com>
	<CAHut+Ps6Y9ZeAXfUntci0NX6tBqNu+Rj1hy8BsuqXPLrXeUvFQ@mail.gmail.com>

Peter Smith <smithpb2250@gmail.com> writes:
> On Thu, Aug 19, 2021 at 4:29 AM Justin Pryzby <pryzby@telsasoft.com> wrote:
>> -       state->oneCol = (origTupdesc->natts == 1) ? true : false;
>> +       state->oneCol = origTupdesc->natts == 1;

FWIW, I am definitely not a fan of removing the parentheses in this
context, because readers might wonder if you meant an "a = b = 1"
multiple-assignment, or even misread it as that and be confused.
So I'd prefer

          state->oneCol = (origTupdesc->natts == 1);

In the context of "return (a == b)", I'm about neutral on whether
to keep the parens or not, but I wonder why this patch does some
of one and some of the other.

I do agree that "x ? true : false" is silly in contexts where x
is guaranteed to yield zero or one.  What you need to be careful
about is where x might yield other bitpatterns, for example
"(flags & SOMEFLAG) ? true : false".  Pre-C99, this type of coding
was often *necessary*.  With C99, it's only necessary if you're
not sure that the compiler will cast the result to boolean.

			regards, tom lane





view thread (27+ messages)  latest in thread

Message-ID: <1673521.1629342537@sss.pgh.pa.us>
Permalink:  ../1673521.1629342537@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1673521.1629342537@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, smithpb2250@gmail.com, pryzby@telsasoft.com, bruce@momjian.us, pgsql-hackers@lists.postgresql.org
  Subject: Re: strange case of "if ((a & b))"
  In-Reply-To: <1673521.1629342537@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox