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
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.
