TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Converting the Kernel to C++

79 点作者 artagnon超过 1 年前

14 条评论

loup-vaillant超过 1 年前
&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 未加载
TwentyPosts超过 1 年前
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;.
synergy20超过 1 年前
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 未加载
charcircuit超过 1 年前
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_kiddo超过 1 年前
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>
azamba超过 1 年前
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 未加载
jraph超过 1 年前
No reply from Linus Torvalds yet! Hoping to find one was half the reason why I clicked on this.
评论 #38945450 未加载
xorcist超过 1 年前
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_krien超过 1 年前
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-yml超过 1 年前
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 未加载
6R1M0R4CL3超过 1 年前
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.
binary132超过 1 年前
Kinda feel like he just wrote this to make the rust folks seethe.
Gow8876超过 1 年前
Should have been titled as Converting the Kernel to Rust. Heck even to Zig would be more appealing.
bfrog超过 1 年前
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 未加载