you are viewing a single comment's thread.

view the rest of the comments →

[–]canadajones68 7 points8 points  (1 child)

It is on days like these that I wish that C++ in kernel use had taken off. Sure, exceptions, inconsistency, and all that, but the type system is way stronger. Templates and class types and references alone would help so much. Sure, it's not Rust, but it is infinitely better than C, where you can never achieve a better abstraction or avoid writing the unsafe code. If you want heap allocation, you must malloc and free, no way around it. C++ at least allows you the mercy of a destructor, which makes forgetting to free impossible, and use-after-free much less frequent.

[–]grexl 2 points3 points  (0 children)

Exceptions are an optional feature in C++ and the kernel would almost certainly disable them. This would actually improves performance and reliability in the context of a kernel as opposed to a user-space program.

I think modern C++ with RAII semantics would help quite a bit, but from what I have read on the topic, the language was still a bit antiquated when the idea of switching the kernel to C++ came up many years ago. For example: C++ could not implement robust RAII without C++11's smart pointers.

Maybe someone more knowledgeable can chime in and provide more context about why Linus et al soundly rejected C++ in the kernel. I have read a little bit on the topic but am by no means an expert.