Re: C aggregate passing (Rust kernel policy)

henrychurchill
2025-02-21T23:03:44Z

---- Original message ----
> From: Linus Torvalds <torvalds@linux-foundation.org>
> To: Jan Engelhardt <ej@inai.de>
> Subject: Re: C aggregate passing (Rust kernel policy)
> Date: 02/21/2025 21:26:02 Europe/Paris
> Cc: David Laight <david.laight.linux@gmail.com>;
> H. Peter Anvin <hpa@zytor.com>;
> Greg KH <gregkh@linuxfoundation.org>;
> Boqun Feng <boqun.feng@gmail.com>;
> Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>;
> Christoph Hellwig <hch@infradead.org>;
> rust-for-linux <rust-for-linux@vger.kernel.org>;
> David Airlie <airlied@gmail.com>;
> linux-kernel@vger.kernel.org;
> ksummit@lists.linux.dev
>
> On Fri, 21 Feb 2025 at 12:06, Jan Engelhardt <ej@inai.de>
wrote:
> >
> > >(Apart from the fact that c++ makes it hard to ensure all
the non-class
> > >members are initialised.)
> >
> > struct stat x{};
> > struct stat x = {};
> >
> > all of x's members (which are scalar and thus non-class)
are
> > initialized. The second line even works in C.
>
> Yeah. People love to talk about "safe C", but compiler people
have
> actively tried to make C unsafer for decades. The C
standards
> committee has been complicit. I've ranted about the crazy C
alias
> rules before.
>

The unsafe subset of Rust has way stricter aliasing rules than
C. You should read up on unsafe before touching it in Rust, it
can get gnarly.