Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGYQU-0000tM-Mt for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Aug 2021 03:09:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mGYQS-0003mg-HM for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Aug 2021 03:09:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGYQS-0003lI-9J for pgsql-hackers@lists.postgresql.org; Thu, 19 Aug 2021 03:09:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGYQN-0005s7-9s for pgsql-hackers@lists.postgresql.org; Thu, 19 Aug 2021 03:09:03 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 17J38vn51673522; Wed, 18 Aug 2021 23:08:57 -0400 From: Tom Lane To: Peter Smith cc: Justin Pryzby , Bruce Momjian , PostgreSQL Hackers Subject: Re: strange case of "if ((a & b))" In-reply-to: References: <20210428182936.GE27406@telsasoft.com> <2896014.1619635209@sss.pgh.pa.us> <20210625023110.GI29179@telsasoft.com> <20210818180222.GE13002@momjian.us> <20210818182856.GR10479@telsasoft.com> Comments: In-reply-to Peter Smith message dated "Thu, 19 Aug 2021 10:59:39 +1000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1673520.1629342537.1@sss.pgh.pa.us> Date: Wed, 18 Aug 2021 23:08:57 -0400 Message-ID: <1673521.1629342537@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Smith writes: > On Thu, Aug 19, 2021 at 4:29 AM Justin Pryzby 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