From: "H. Peter Anvin" <hpa@zytor.com>
To: Bart Van Assche <bvanassche@acm.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: James Bottomley <James.Bottomley@hansenpartnership.com>,
ksummit@lists.linux.dev, Dan Williams <dan.j.williams@intel.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: Clarifying confusion of our variable placement rules caused by cleanup.h
Date: Tue, 18 Nov 2025 11:15:35 -0800 [thread overview]
Message-ID: <7e01e70c-4a6a-41f5-a059-1434331ecaae@zytor.com> (raw)
In-Reply-To: <82a250e0-de9e-467a-882e-7acefbfd7c24@acm.org>
On 2025-11-18 11:04, Bart Van Assche wrote:
> On 11/18/25 10:38 AM, Linus Torvalds wrote:
>> Now, we currently don't use __auto_type very much outside of macros
>> (and there we often use "typeof(x)" instead for historical compiler
>> reasons), but I suspect we probably should. There's a patch floating
>> around that makes it more convenient with a
>>
>> #define auto __auto_type
>>
>> because the historical C 'auto' keyword has been so completely and
>> utterly useless.
>
> In a C++ style guide I found the following advice for type deduction:
>
> "Use type deduction only if it makes the code clearer to readers who
> aren't familiar with the project, or if it makes the code safer. Do not
> use it merely to avoid the inconvenience of writing an explicit type."
>
> However, I'm not sure whether this guidance also makes sense for C kernel
> code. See also
> https://google.github.io/styleguide/cppguide.html#Type_deduction
>
The "makes code clearer or safer" seems like a good idea to me.
Notably the following constructs, mostly used in macros:
typeof(x) _x = (x);
typeof(z) _y = (typeof(z)) (y);
... are really quite dangerous because it is very easy to mistakenly put the
wrong variable inside the typeof().
-hpa
next prev parent reply other threads:[~2025-11-18 19:15 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 16:39 Clarifying confusion of our variable placement rules caused by cleanup.h James Bottomley
2025-11-18 17:18 ` Bart Van Assche
2025-11-18 18:38 ` Linus Torvalds
2025-11-18 19:04 ` Bart Van Assche
2025-11-18 19:14 ` Linus Torvalds
2025-11-18 20:43 ` Al Viro
2025-11-18 19:15 ` H. Peter Anvin [this message]
2025-11-18 19:11 ` H. Peter Anvin
2025-11-18 19:16 ` Linus Torvalds
2025-11-18 19:19 ` H. Peter Anvin
2025-11-18 19:17 ` Steven Rostedt
2025-11-18 19:22 ` Linus Torvalds
2025-11-18 19:56 ` Steven Rostedt
2025-11-18 20:23 ` Linus Torvalds
2025-11-18 21:05 ` Linus Torvalds
2025-11-18 20:21 ` James Bottomley
2025-11-18 20:30 ` Linus Torvalds
2025-11-18 20:51 ` Steven Rostedt
2025-11-18 21:10 ` James Bottomley
2025-11-18 22:34 ` Steven Rostedt
2025-11-18 23:32 ` James Bottomley
2025-11-18 19:23 ` H. Peter Anvin
2025-11-18 20:28 ` James Bottomley
2025-11-25 13:09 ` Jani Nikula
2025-11-25 14:25 ` Alexey Dobriyan
2025-11-25 15:32 ` Stephen Hemminger
2025-11-25 16:04 ` Steven Rostedt
2025-11-25 17:57 ` H. Peter Anvin
2025-12-31 12:17 ` Andy Shevchenko
2026-01-02 14:50 ` Steven Rostedt
2026-01-17 16:23 ` Alexey Dobriyan
2026-01-17 16:54 ` Bird, Tim
2026-01-17 23:32 ` David Laight
2026-01-18 16:04 ` Steven Rostedt
2026-01-18 19:12 ` Paul E. McKenney
2026-01-18 19:17 ` James Bottomley
2026-01-18 19:33 ` Dan Carpenter
2026-01-18 19:52 ` Joe Perches
2026-01-18 21:07 ` Steven Rostedt
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=7e01e70c-4a6a-41f5-a059-1434331ecaae@zytor.com \
--to=hpa@zytor.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=bvanassche@acm.org \
--cc=dan.carpenter@linaro.org \
--cc=dan.j.williams@intel.com \
--cc=ksummit@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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