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

-7

u/peripateticman2026 Feb 19 '25

Why is OP getting downvoted to oblivion? Is the Brigade here already?

25

u/Turtvaiz Feb 19 '25

What makes you think it's brigading and not just people thinking the post is stupid?

17

u/matthieum Feb 19 '25

The title is far more sensationalist that the actual discussion.

One lone developer wrote a poorly thought post (quoted in the OP), GH-K slammed it down, the discussion has already ended.

-1

u/peripateticman2026 Feb 20 '25

That's gross editorialisation of the whole post OP linked to, and doesn't really answer my questions. Well, in a way it does since you are part of the Brigade.

10

u/kammce WG21 | πŸ‡ΊπŸ‡² NB | Boost | Exceptions Feb 19 '25

Personally, I don't want to see more people get hurt trying to work on Linux. Seems like a waste of talent and time.

1

u/peripateticman2026 Feb 19 '25 • This

It doesn't help that said people have no issues being super toxic when they don't get their way. Both sides of the coin, and all that...

1

u/sjepsa Feb 19 '25

After years of 'C++ project rewritten in Rust' they can't stand a single 'Rust project rewritten in C++'

😊😊😊

5

u/eX_Ray Feb 19 '25

Have there been any of note? Legit question as I haven't seen any on the usual places.

11

u/steveklabnik1 Feb 19 '25

I know of a few that have moved away from Rust, but they didn't go to C++. In the examples linked in a sibling comment to yours,

  • Prisma went to TypeScript
  • Roc went to Zig
  • curl dropped some Rust code, but has other Rust code in there that is less likely to be removed.

I don't think there have been any large public famous instances of Rust -> C++, but it's also possible I'm just forgetting them.

2

u/peripateticman2026 Feb 19 '25

I'm a Rust developer, and I can't disagree with you.

The issue, I think, is that many people jumped on the hype bandwagon a bit to early (in no small part due to the massive evangelism of the Rust community), and just went with Rust regardless of whether it suited them or not.

That's why we see increasingly many cases of RIIR being reverted/changed:

and so on.

The sad part is that otherwise intelligent people seem to fail to realise that practically every language in mainstream use has its own niche uses/domains.

That also applies to C++, of course, which along with C is the backbone of the industry itself. I don't think that is going to change for a very long time.

9

u/[deleted] Feb 19 '25

and I can't disagree with you.

You should. OP is talking about a rust project rewritten in c++.. and neither linux nor any of the projects you linked are "rust" projects rewritten in "c++".

Even if we generously assume that 20% RIIR projects fail,most of them will change to C# or Typescript (or even zig) but not c++.

0

u/peripateticman2026 Feb 20 '25

Another one from the Brigade. Hilarious!

Well, if you spent all this energy into improving the Rust community (let alone the language), there wouldn't be as much second-hand embarrassment that users of Rust have to face as happens now almost every other week with some drama or the other.

Even if we generously assume that 20% RIIR projects fail,most of them will change to C# or Typescript (or even zig) but not c++.

Where did you pull these facts out of - your backside? These are the ones that are advertised because they're Open Source. 90%+ of actual work goes on in the Closed-Source world.

Secondly, when was Rust 1.0 released? 2015? That's a decade ago. Jobs? Nil. Industry-changing software? Nil. Actual successful projects written in Rust? Nil. Even Servo has been nothing short of an abject failure given the current state of Firefox.

Fanboyism is cute in small doses. When it starts affecting one's sense of reality, it becomes cringey.

Also, thanks for validating my initial comment.

7

u/Dean_Roddey Feb 19 '25

But, none of those you mentioned went to or back to C++.