|
|
Log in / Subscribe / Register

The 5.7 kernel is out

The 5.7 kernel is out

Posted Jun 2, 2020 21:10 UTC (Tue) by excors (subscriber, #95769)
In reply to: The 5.7 kernel is out by mathstuf
Parent article: The 5.7 kernel is out

I assume they meant RTTI, not RAII. RTTI is inefficient and mostly useless. RAII is great, like a more general version of the devm_ API that lets you eliminate large classes of resource-leak bugs with zero overhead.

In a kernel context, "C++" should always be interpreted as "C++ with no exceptions, no RTTI, no STL containers, no std::thread, no new/delete (except for placement new), etc". Issues like std::vector<bool> are irrelevant - any serious embedded developer is always going to implement their own container library to suit their own requirements (like giving the container's owner more control over memory allocation, and not using exceptions to signal errors).

That subset of C++ isn't standardised, but it's widely used (with minor variations) and it's not that hard to stick to. If you don't provide header files for STL containers then nobody will accidentally use them. If you don't define 'operator new' then nobody will accidentally call it instead of your custom memory allocator. A kernel has enough control of its build environment to guarantee those things.

Then you still get useful stuff like RAII, templates, stronger type checking, less reliance on horrific macros, the ability to do automatic refcounting, lambdas, std::unique_ptr, std::atomic, etc. Nothing individually of world-changing importance, but it's a lot of tools that let you design APIs that are easier to use correctly and/or harder to use incorrectly than in C, increasing code quality and avoiding bugs. And you still retain control over every function call and every byte of stack usage when you care about that. And it's a language that millions of programmers are already familiar with (including many already working in resource-constrained environments, and probably a lot of Linux developers who've worked outside the kernel too), and that you can incrementally transition to from C.


to post comments

The 5.7 kernel is out

Posted Jun 3, 2020 7:10 UTC (Wed) by marcthe12 (guest, #135461) [Link]

True but the point my comment is that the better option is to use an another language that is design for that space. Zig matches that but lets say its still not mature enough


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds