Re: [PATCH] Use ^=1 to toggle between 0 and 1
- From
- phillip.wood123@gmail.com <phillip.wood123@gmail.com>
- Date
- Dec 21, 2023, 15:06 UTC
- Message-ID
- <23d47364-9ec2-4273-8ea5-f106550e125a@gmail.com>
- In-Reply-To
- <20231221095606.GB570888@coredump.intra.peff.net>
Hi Peff
On 21/12/2023 09:56, Jeff King wrote:
Show 11 quoted lines
> On Fri, Dec 15, 2023 at 02:46:36PM +0000, Phillip Wood wrote: > >>> Yeah. b2() is wrong for passing "2" to a bool. >> >> I think it depends what you mean by "wrong" §6.3.1.2 of standard is quite >> clear that when any non-zero scalar value is converted to _Bool the result >> is "1" > > Yeah, sorry, I was being quite sloppy with my wording. I meant "wrong" > as in "I would ideally flag this in review for being weird and > confusing".
That makes sense, it certainly is confusing
> Of course there are many reasonable cases where you might pass an > integer "foo" rather than explicitly booleanizing it with "!!foo". So I > do agree it's a real potential problem (and I'm sufficiently convinced > that we should avoid an "int" fallback if we can).
I had a look at gnulib the other day and the list of limitations in the documentation of their <stdbool.h> fallback makes it look quite unattractive. They helpfully list some compilers where _Bool is not implemented (IRIX, Tru64) or does not work correctly (HP-UX, AIX). As far as I can see all the bug reports cited are from 2003-2006 on obsolete compiler versions, hopefully _Bool is better supported these days.
Best Wishes
Phillip
> -Peff