From: Segher Boessenkool <segher@kernel.crashing.org>
To: Bill Wendling <morbo@google.com>
Cc: paulmck@kernel.org, linux-toolchains@vger.kernel.org
Subject: Re: Do we care if C compilers start allowing "." on pointers?
Date: Sat, 11 Jan 2025 01:55:55 -0600 [thread overview]
Message-ID: <20250111075555.GS20626@gate.crashing.org> (raw)
In-Reply-To: <CAGG=3QWKVpoZAh_yD=15pkbRUVSeAmt5DJ94hKfxJ5HfTqV=Rg@mail.gmail.com>
Hi!
On Fri, Jan 10, 2025 at 05:09:21PM -0800, Bill Wendling wrote:
> On Fri, Jan 10, 2025 at 7:02 AM Paul E. McKenney <paulmck@kernel.org> wrote:
> > Currently, given a pointer "p", C allows p->a but not p.a. There is a
> > proposal from C++ [1] that is being considered for C.
> >
> > Do we care?
> >
> Does the proposal seem likely to be added to C++? The motivation is
> very weak, in my opinion.
Yes. Especially this part:
"""Other languages (JS,Rust,Ruby,Python,Go,C#,Java,Kotlin,Swift,ObjC),
indirectly derived from C have come to just use '.' as an operator;"""
The only way that those languages can be said to be indirectly derived
from C is that they have similar syntax. With quite different semantics
in most cases, of course.
> Other languages are very different from
> C/C++; they try to hide away memory management details, which are a
> major part of C languages. (To prevent a holy war, my comments aren't
> about the benefits and drawbacks of memory management in other
> languages.)
The distinction between . and -> helps the user avoid many common stupid
mistakes. This proposal makes life harder for the user. If that is the
actual goal here, good proposal then, but otherwise, not so much.
> As for the kernel, if C/C++ adopt this convention, we won't be able to
> accept contributions which use '.' to access pointers until the
> minimum version of the compilers support this feature, which I imagine
> will take several years. My personal opinion would be to require '->'
> even when the option is available, unless a much better motivation is
> made.
With "several" being at least seven. Yes. And it would make sense to
stay close to the old coding style stuff anyway, it has proven its
value.
Btw. I can guarantee there will be a warning for ". used on a pointer".
Read that as a prommise if you want :-) And although I always say that
-Werror is one of the worst ideas of the last decade, I would support
doing -Werror=pointer-dot for all of the kernel. It's not so bad there:
actually upgrading a warning to an error is a user choice (while doing
this only so that others cannot as easily ignore the warnings, i.e. the
usual case, is the worst kind of bureaucracy).
Segher
next prev parent reply other threads:[~2025-01-11 8:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 15:02 Do we care if C compilers start allowing "." on pointers? Paul E. McKenney
2025-01-11 1:09 ` Bill Wendling
2025-01-11 5:25 ` Paul E. McKenney
2025-01-11 7:55 ` Segher Boessenkool [this message]
2025-01-12 19:57 ` Florian Weimer
2025-01-13 22:01 ` Bill Wendling
2025-01-11 17:12 ` David Malcolm
2025-01-12 17:37 ` Paul E. McKenney
2025-01-13 23:50 ` Jason Merrill
2025-01-14 18:47 ` Paul E. McKenney
2025-01-13 11:16 ` Peter Zijlstra
2025-01-14 18:48 ` Paul E. McKenney
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=20250111075555.GS20626@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=linux-toolchains@vger.kernel.org \
--cc=morbo@google.com \
--cc=paulmck@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.