[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221019212631.GR25951@gate.crashing.org>
Date: Wed, 19 Oct 2022 16:26:31 -0500
From: Segher Boessenkool <segher@...nel.crashing.org>
To: David Laight <David.Laight@...lab.com>
Cc: "'Linus Torvalds'" <torvalds@...ux-foundation.org>,
"Jason A. Donenfeld" <Jason@...c4.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-kbuild@...r.kernel.org" <linux-kbuild@...r.kernel.org>,
"linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
"linux-toolchains@...r.kernel.org" <linux-toolchains@...r.kernel.org>,
Masahiro Yamada <masahiroy@...nel.org>,
Kees Cook <keescook@...omium.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH] kbuild: treat char as always signed
On Wed, Oct 19, 2022 at 09:07:01PM +0000, David Laight wrote:
> From: Linus Torvalds
> > Sent: 19 October 2022 19:11
> > Explicit casts are bad (unless, of course, you are explicitly trying
> > to violate the type system, when they are both required, and a great
> > way to say "look, I'm doing something dangerous").
> Casts really ought to be rare.
Sometimes you need casts for *data*, like where you write (u32)smth
because you really want the low 32 bits of that something. That only
happens in some kinds of code -- multi-precision integer, some crypto,
serialisation primitives.
You often want casts for varargs, too. The alternative is to make very
certain some other way that the actual arguments will have the correct
type, but that is often awkward to do, and not as clear to read.
Pointer casts are almost always a mistake. If you think you want one
you are almost always wrong.
Segher
Powered by blists - more mailing lists