From: Ingo Molnar <mingo@kernel.org>
To: Jiri Slaby <jirislaby@kernel.org>
Cc: Uros Bizjak <ubizjak@gmail.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH 1/2] x86/bootflag: Change some static functions to bool
Date: Mon, 24 Feb 2025 19:58:39 +0100 [thread overview]
Message-ID: <Z7zBXyywUEC2ieiR@gmail.com> (raw)
In-Reply-To: <ef6e2925-f005-41e9-bc24-b9adc3922706@kernel.org>
* Jiri Slaby <jirislaby@kernel.org> wrote:
> On 24. 02. 25, 8:39, Uros Bizjak wrote:
> > The internal compiler representation of the following testcase:
> >
> > _Bool foo (int x) { return x; }
> >
> > is:
> >
> > --cut here--
> > _Bool foo (int x)
> > {
> > _Bool _2;
> >
> > <bb 2> [local count: 1073741824]:
> > _2 = x_1(D) != 0;
> > return _2;
>
> Yes, exactly as dictated by the C99 standard.
>
> > }
> > --cut here--
> >
> > For me, !!x in the source means that the change of types was
> > intentional. Surely, the compiler can do it by itself, so at the end
> > of the day, it is just a matter of personal taste.
>
> I've just learnt, that we even have that in CodingStyle:
> ===
> > 17) Using bool
> > --------------
> >
> > The Linux kernel bool type is an alias for the C99 _Bool type. bool values can
> > only evaluate to 0 or 1, and implicit or explicit conversion to bool
> > automatically converts the value to true or false. When using bool types the
> > !! construction is not needed, which eliminates a class of bugs.
> ===
This rule doesn't apply here, because the !! operation isn't done on
bool types: 'x' in the parity() function is an 'int'...
So this CodingStyle entry is a red herring, and the !! is absolutely
used in the kernel as an explicit marker of intentional type conversion
to bool.
Thanks,
Ingo
next prev parent reply other threads:[~2025-02-24 18:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-29 15:47 [PATCH 1/2] x86/bootflag: Change some static functions to bool Uros Bizjak
2025-01-29 15:47 ` [PATCH 2/2] x86/bootflag: Use __builtin_parity() when available Uros Bizjak
2025-01-31 15:15 ` Uros Bizjak
2025-02-22 11:56 ` [tip: x86/boot] x86/boot: Change some static bootflag functions to bool tip-bot2 for Uros Bizjak
2025-02-24 7:18 ` [PATCH 1/2] x86/bootflag: Change some static " Jiri Slaby
2025-02-24 7:24 ` Uros Bizjak
2025-02-24 7:27 ` Jiri Slaby
2025-02-24 7:39 ` Uros Bizjak
2025-02-24 7:48 ` Jiri Slaby
2025-02-24 7:56 ` Uros Bizjak
2025-02-24 18:58 ` Ingo Molnar [this message]
2025-02-26 6:31 ` Jiri Slaby
2025-02-26 7:17 ` H. Peter Anvin
2025-02-26 7:21 ` Jiri Slaby
2025-02-26 12:21 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z7zBXyywUEC2ieiR@gmail.com \
--to=mingo@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox