r/cpp • • Jul 13 '22

Why does Linus hate C++ ?

308 Upvotes

436 comments sorted by

View all comments

Show parent comments

-2

u/top_logger Jul 13 '22

OOP + exceptions + STL = bad idea for kernel even in C++20(which is still not fully available now).

I find C++ great, still you need good engineers and kind of reality understanding.

33

u/Mason-B Jul 13 '22 edited Jul 13 '22

Every single thing you listed there is optional (if we understand "OOP" as virtual methods/inheritance, which is how people generally mean it). While on the topic, Rust's abort mechanism also doesn't fly for exceptions in a kernel either.

Any language being used in a kernel environment will necessarily be restricted and modified. Neither C++, nor Rust, nor even C escape that. Listing optional features as problems isn't a sane counter example.

7

u/simonask_ Jul 13 '22

While on the topic, Rust's abort mechanism also doesn't fly for exceptions in a kernel either.

I have to point out that Rust's panic machinery is exactly what you want in a kernel. Yes, the default panic handler unwinds the stack and terminates only the current thread, but setting panic = abort to immediately call abort() is a first-class option, and panics occur in Rust exactly where you would want a kernel to panic.

With strong memory guarantees and the safe/unsafe distinction, I literally could not imagine a better language for a kernel.

6

u/Mason-B Jul 13 '22

Except not (according to Linus) because Rust's Panic is not a valid situation to Kernel Panic.

I do think that the "run-time failure panic" is a fundamental issue.

this is simply fundamentally not acceptable.

With the main point of Rust being safety, there is no way I will ever accept "panic dynamically" (whether due to out-of-memory or due to anything else - I also reacted to the "floating point use causes dynamic panics") as a feature in the Rust model.

→ More replies (2)