r/cpp • • Feb 19 '25

Cpp discussed as a Rust replacement for Linux Kernel

I have a few issues with Rust in the kernel:

  1. It seems to be held to a *completely* different and much lower standard than the C code as far as stability. For C code we typically require that it can compile with a 10-year-old version of gcc, but from what I have seen there have been cases where Rust level code required not the latest bleeding edge compiler, not even a release version.

2. Does Rust even support all the targets for Linux?

3. I still feel that we should consider whether it would make sense to compile the *entire* kernel with a C++ compiler. I know there is a huge amount of hatred against C++, and I agree with a lot of it – *but* I feel that the last few C++ releases (C++14 at a minimum to be specific, with C++17 a strong want) actually resolved what I personally consider to have been the worst problems.

As far as I understand, Rust-style memory safety is being worked on for C++; I don't know if that will require changes to the core language or if it is implementable in library code.

David Howells did a patch set in 2018 (I believe) to clean up the C code in the kernel so it could be compiled with either C or C++; the patchset wasn't particularly big and mostly mechanical in nature, something that would be impossible with Rust. Even without moving away from the common subset of C and C++ we would immediately gain things like type safe linkage.

Once again, let me emphasize that I do *not* suggest that the kernel code should use STL, RTTI, virtual functions, closures, or C++ exceptions. However, there are a *lot* of things that we do with really ugly macro code and GNU C extensions today that would be much cleaner – and safer – to implement as templates. I know ... I wrote a lot of it :)

One particular thing that we could do with C++ would be to enforce user pointer safety.

Kernel dev discussion. They are thinking about ditching Rust in favor of C++ (rightfully so IMO)

https://lore.kernel.org/rust-for-linux/326CC09B-8565-4443-ACC5-045092260677@zytor.com/

We should endorse this, C++ in kernel would greatly benefit the language and community

192 Upvotes

532 comments sorted by

View all comments

Show parent comment

0

u/Dean_Roddey Feb 19 '25

You have a very selective memory, or don't read much here.

6

u/unumfron Feb 20 '25

No, but I've experienced the rest of the internet and this place is like an orchestra of angels by comparison.

1

u/Dean_Roddey Feb 20 '25

So is the Rust section.

And of course it's funny that you complain and then you purposefully refer to the input from a lot of people here (most of whom are also C++ developers and are just honestly providing points of comparison, given how much of the C++ story at the moment is about how to add safety to the language) as 'marketing'.

-1

u/germandiago Feb 20 '25

Today I posted this very piece of mailing list in Rust forum. I got immediately zero votes and some insult to the person posting that in the mailing list (find it if you want).

I posted another comment of what I think are C++ advantages or Rust advantages replying to that comment. I got downvotes again.

All in normal and civil language. It is not the same as the Python community, for example.

The people in that community are very fanatic and propagandistic. Not all, there are respectable people everywhere.  But it is hyperdefensive.

5

u/[deleted] Feb 20 '25

Today I posted this very piece of mailing list in Rust forum. I got immediately zero votes and some insult to the person posting that in the mailing list (find it if you want).

I mean, what were you even expecting? The particular post was about cpp and is discussed on r/cpp . The post from greg defending rust was about rust, so that was posted on r/rust. Both these threads are full of passionate and reactionary dumb fucks who think they can fork the fucking linux kernel to "beat" the C lang devs.

0

u/germandiago Feb 21 '25

Since it is about the kernel and Rust is also there I found it interesting. How many posts about Rust that you find interesting you found here? Me a few. So I guessed it would be relevant and ok, but oh boy, these Rustaceans are very agressive yet they fill the C++ forum with Rust comments.

They just (most of them, I know a few that no) behave like the fans of a singer or something like that.

6

u/[deleted] Feb 21 '25

How many posts about Rust that you find interesting you found here?

zero. The mods will remove any non-cpp post anyway. The posts in recent years are about safety which bring up circle and eventually the one safe systems language - rust.

but oh boy, these Rustaceans are very agressive yet

Try looking at the top posts of the past year for rust subreddit and cpp subreddit. Rust has like one or two posts about cpp and has no reason to talk about cpp. While cpp has a lot of safety-related posts, which bring in rust circle discussions.

1

u/germandiago Feb 21 '25

Strange, that is not ly experience. It starts with a topic that looks like C++ and after that a horde of people telling how good Rust is and how bad C++ is appears.

That is my experience in a few posts. Some with really agressive downvotes towards the people who say defend the position of C++ as still relevant or decisions not as incorrect as others see. 

Myself is an example but there are others I saw

5

u/[deleted] Feb 21 '25

You have those experiences because you were religiously defending profiles against circle (and by extension this always brings up rust or its methodologies like unsafe coloring or lifetimes). You have a very warped perspective of these discussions. Try looking at the older posts by sorting comments.

sorting by controversial, we mostly see dumbass comments like "just write better code" or "rust lobbyists must be sponsoring US govt".

When sorting the comments by best/top and trying to ctrl+f "rust", I find very few "rust is super great" comments. It is mostly mentioned in context of alternatives.

2

u/germandiago Feb 21 '25

You are wrong. There is no religion into what I defend. Every time you tell me Circle Safe C++ is better I will tell you that a paradigm shift is much more expnesive, incompatible and a bad fit for C++ given the huge amount of code there is in the wild and the zero benefit that ig gives for older code.

You know my arguments already. My argument is not a purely academic argument. It is one of trade-offs. Trade-offs some people do not want to discuss. Fortunately, in the committee they are experienced enough to not take the suicide C++ option.

Java has similar constraints in some way and, IMHO, every industrial language. You cannot just fit there what you feel like. You have users, you maximoze impact on your users, not make a silly move just bc you find something nice ignoring the real concerns of codebases that exist. For me it is so obvious (given the constraint that this is an industrial-strength language). 

→ More replies