> <i>We do a lot of metaprogramming in the Linux kernel, implemented with
some often truly hideous macro hacks.</i><p>If you do a lot of meta-programming… why not used a more principled approach like Lex & Yacc? Why not go all the way to design mini-languages and compile them to C? Or design C extensions and compile them to C? You can still have good debugging support with line markers. <a href="https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html" rel="nofollow">https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html</a>
Using a small set(kernel-c++20) it can simplify the existing C code by quite a bit, you get ctor, dtor, class inheritance etc all for free. Currently the kernel is basically in object-oriented C anyways.
I'm skeptical that this is better than starting to rewrite the kernel in Rust. It would be better if everyone can focus on rewriting things into Rust rather than having a choice of rewriting into C++ or Rust. Unlike this email, C can be converted into Rust piecemeal and integrate with the rest of the kernel. It's also in kernel developers best interest to start learning Rust, and getting them to start earlier than later will be beneficial.
Somewhat related: In 2020 gcc bumped the requirement for bootstrapping to be a C++11 compiler [0]. Would have been fun to see the kernel finally adopt C++14 as the author suggested.<p>I don't think that Linus will allow this since he just commented that he will allow rust in drivers and major subsystems [1].<p>would have hoped see more answers or see something in here from actual kernel developers.<p>0: <a href="https://github.com/gcc-mirror/gcc/commit/5329b59a2e13dabbe2038af0fe2e3cf5fc7f98ed">https://github.com/gcc-mirror/gcc/commit/5329b59a2e13dabbe20...</a><p>1: <a href="https://youtu.be/YyRVOGxRKLg?si=_ad7wU51bDdDg6Ic&t=104" rel="nofollow">https://youtu.be/YyRVOGxRKLg?si=_ad7wU51bDdDg6Ic&t=104</a>
Old but gold <a href="https://harmful.cat-v.org/software/c++/linus" rel="nofollow">https://harmful.cat-v.org/software/c++/linus</a>
As with all good writing, it is hard for me to tell serious suggestions from satire.<p>However, hpa seems to be the crazy genius type, so maybe it's all for real.<p>The thing I'd like to know is, given that the kernel is written in "kernel C", a shared culture about how C should be used together with a hairy mountain of macros, why not make kernel-C a proper language?<p>It's probably just a number of extensions away. Together with some rules about code generation, it could make for a fairly neat dialect of C that would be much easier to use and understand. It would also pave the way for further experiments with compile time guarantees about soundness of isolated sections of the code.<p>Because, and we should be honest about this, going any C++-like route would impact the long term quality of submitted code. There should be no technical reason for this, but that does not make it something that should be turned a blind eye on.
does this have implications on the place of c in the programming world?
I am seeing this trend in HPC and systems programming to move into more structured languages. even FORTRAN has objects now.<p>gives me some doubts if I should put my time into learning c or not.
a lot of the tech I care about uses c++ (i want to work in ANNs) and true the kernels are basically in c but the code is c++.
The path to migrate to Zig is, or would be, the most straightforward, except that that language is not ready. But in design terms it's definitely got the things the OP is championing C++ for, and a better story for actually addressing longstanding systems programming issues instead of heaping stuff onto the C toolchain and therefore making everyone debug C build-time errors.
perhaps it is possible. modern c++ is quite different from the previous incarnations of c++ but when you are writing kernel code.. you have in a space where a lot of stuff is not available : you are running in the kernel context. the userland part is waiting for you to give control back, so your code must be fast, do the required job, and be predictible. we cannot have a line of code that will, sometimes, create a huge cpu or memory load because a lot of stuff is going to happen behind it. that's why C is so effective... the kernel context is not a place where you can have garbage collection or classes-stuff that will happen when you're supposed to get control back to userland as quickly as possible.
What’s the benefit? Rust actually is a nice language. C++ requires deciding which features to use? I don’t know modern C++ but it seems to have a kind of cult like indoctrination where everything else is wrong and only each persons flavor is correct leading to endless bike shedding.<p>C may have technical challenges but seemingly personal preferences are much more limited, just like the language. That helps large projects move forward.