From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0E1FC433FE for ; Wed, 19 Oct 2022 21:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230264AbiJSV3s (ORCPT ); Wed, 19 Oct 2022 17:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiJSV3q (ORCPT ); Wed, 19 Oct 2022 17:29:46 -0400 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6B1B44544; Wed, 19 Oct 2022 14:29:43 -0700 (PDT) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 29JLQXd0021146; Wed, 19 Oct 2022 16:26:33 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 29JLQV9c021145; Wed, 19 Oct 2022 16:26:31 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Wed, 19 Oct 2022 16:26:31 -0500 From: Segher Boessenkool To: David Laight Cc: "'Linus Torvalds'" , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" , "linux-kbuild@vger.kernel.org" , "linux-arch@vger.kernel.org" , "linux-toolchains@vger.kernel.org" , Masahiro Yamada , Kees Cook , Andrew Morton , Andy Shevchenko , Greg Kroah-Hartman Subject: Re: [PATCH] kbuild: treat char as always signed Message-ID: <20221019212631.GR25951@gate.crashing.org> References: <20221019162648.3557490-1-Jason@zx2c4.com> <20221019165455.GL25951@gate.crashing.org> <20221019174345.GM25951@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org 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