Live data from Hacker News

Converting the Kernel to C++

lore.kernel.org

1–10 of 56 posts

Re: Converting the Kernel to C++

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

Re: Converting the Kernel to C++

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

Re: Converting the Kernel to C++

#6

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 la…

> Unlike this email, C can be converted into Rust piecemeal and integrate with the rest of the kernel.

Did you read the entire email? Here's a quote that seems to directly contradict you:

> converting C code to Rust isn't something that can be done piecemeal, whereas with some cleanups the existing C code can be compiled as C++.

As far as I can tell, the author is correct. What is the pattern for converting C to Rust piecemeal?

Re: Converting the Kernel to C++

#7
post #4

Old but gold https://harmful.cat-v.org/software/c++/linus

EDIT: I failed to notice the date stamp, you can ignore this.

Jeeze. Linus writes like C++ killed his dog or something.

There's plenty of great C++ 'wins' over C that make just doing everyday programming tasks so much easier and simpler for no cost.

You don't need to write so abstract and in the clouds that it becomes impossible to maintain - I certainly don't.

And frankly, you can shoot yourself in the foot just as easily with C, just in different ways.

To be clear: I'm not saying the kernel needs C++, I'm not qualified to write on that specifically. But I am saying C++ is not nearly as bad as he makes it out to be.

Re: Converting the Kernel to C++

#8
post #6

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 la…

> Unlike this email, C can be converted into Rust piecemeal and integrate with the rest of the kernel. Did you read the entire email? Here's a quote that seems to directly contradict you: > converting C code to Rust isn't something that can be done piecemeal, whereas with some cleanups the existing C code can be compiled as C++. As far as I can tell, the author is correct. What is the pattern for converting C to Rust…

>What is the pattern for converting C to Rust piecemeal?

You take a piece and either rewrite it yourself or use a transpiler that produces potentially unsafe Rust code which you then later would want to rewrite into safe Rust code.

Re: Converting the Kernel to C++

#10
> We do a lot of metaprogramming in the Linux kernel, implemented with some often truly hideous macro hacks.

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. https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html

Post reply on HN