TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Converting the Kernel to C++

79 pointsby artagnonover 1 year ago

14 comments

loup-vaillantover 1 year ago
&gt; <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 &amp; 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:&#x2F;&#x2F;gcc.gnu.org&#x2F;onlinedocs&#x2F;cpp&#x2F;Preprocessor-Output.html" rel="nofollow">https:&#x2F;&#x2F;gcc.gnu.org&#x2F;onlinedocs&#x2F;cpp&#x2F;Preprocessor-Output.html</a>
评论 #38946728 未加载
TwentyPostsover 1 year ago
Please, anything but that.<p>I find it hard not to view stuff like this as a &quot;if Rust gets to be in the kernel, then so should C++!&quot;.
synergy20over 1 year ago
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.
评论 #38943164 未加载
charcircuitover 1 year ago
I&#x27;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&#x27;s also in kernel developers best interest to start learning Rust, and getting them to start earlier than later will be beneficial.
评论 #38943383 未加载
评论 #38943890 未加载
评论 #38943108 未加载
kwant_kiddoover 1 year ago
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&#x27;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:&#x2F;&#x2F;github.com&#x2F;gcc-mirror&#x2F;gcc&#x2F;commit&#x2F;5329b59a2e13dabbe2038af0fe2e3cf5fc7f98ed">https:&#x2F;&#x2F;github.com&#x2F;gcc-mirror&#x2F;gcc&#x2F;commit&#x2F;5329b59a2e13dabbe20...</a><p>1: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;YyRVOGxRKLg?si=_ad7wU51bDdDg6Ic&amp;t=104" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;YyRVOGxRKLg?si=_ad7wU51bDdDg6Ic&amp;t=104</a>
azambaover 1 year ago
Old but gold <a href="https:&#x2F;&#x2F;harmful.cat-v.org&#x2F;software&#x2F;c++&#x2F;linus" rel="nofollow">https:&#x2F;&#x2F;harmful.cat-v.org&#x2F;software&#x2F;c++&#x2F;linus</a>
评论 #38943123 未加载
jraphover 1 year ago
No reply from Linus Torvalds yet! Hoping to find one was half the reason why I clicked on this.
评论 #38945450 未加载
xorcistover 1 year ago
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&#x27;s all for real.<p>The thing I&#x27;d like to know is, given that the kernel is written in &quot;kernel C&quot;, 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&#x27;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.
neva_krienover 1 year ago
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++.
crq-ymlover 1 year ago
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&#x27;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.
评论 #38944882 未加载
评论 #38945451 未加载
6R1M0R4CL3over 1 year ago
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&#x27;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&#x27;re supposed to get control back to userland as quickly as possible.
binary132over 1 year ago
Kinda feel like he just wrote this to make the rust folks seethe.
Gow8876over 1 year ago
Should have been titled as Converting the Kernel to Rust. Heck even to Zig would be more appealing.
bfrogover 1 year ago
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.
评论 #38946056 未加载
评论 #38946026 未加载