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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How to translate a large C project to Rust

158 点作者 vmbrasseur超过 8 年前

2 条评论

duneroadrunner超过 8 年前
For the author:<p>You might consider using SaferCPlusPlus[1] as an intermediate step. Most C code translates easily (and automatably if you&#x27;re already parsing the C code) into SaferCPlusPlus. This already gives you memory safety, if that is the goal.<p>Next, you can translate to &quot;rustesque&quot; SaferCPlusPlus. SaferCPlusPlus provides elements (pointer types) that (loosely) correspond to Rust elements [2]. The borrow checker&#x27;s rule of &quot;mutable reference exclusivity&quot; would have to be additionally self-imposed. As you know, this is the hard (difficult to automate) part, but the nice thing is that even partially completed translations&#x2F;rustifications would remain fully functional (and memory safe).<p>The idea is that &quot;rustified&quot; SaferCPlusPlus code should translate to Rust fairly easily. There seems to be some skepticism of the notion of a &quot;rusty&quot; C&#x2F;C++ subset that could be easily translated to valid Rust. The claim seems to be that &quot;lifetime annotation&quot; is essential to the way Rust achieves memory safety without run-time overhead. But others point out that explicit lifetime annotation is not required to evaluate memory safety [3]. It just allows the programmer to express additional intent&#x2F;expectations about object lifetimes.<p>Particularly for an application like CVS, I think translation to SaferCPlusPlus is clearly the more expedient solution. Again, the benefits of (intermediate) translation to SaferCPlusPlus: i) You get memory safety in step 1, and ii) all intermediate steps remain functional and memory safe.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;duneroadrunner&#x2F;SaferCPlusPlus" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;duneroadrunner&#x2F;SaferCPlusPlus</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;duneroadrunner&#x2F;SaferCPlusPlus#safercplusplus-versus-rust" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;duneroadrunner&#x2F;SaferCPlusPlus#safercplusp...</a><p>[3] <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;31609137&#x2F;why-are-explicit-lifetimes-needed-in-rust#31612025" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;31609137&#x2F;why-are-explicit...</a>
评论 #13147327 未加载
评论 #13157440 未加载
评论 #13147757 未加载
drewm1980超过 8 年前
This is a really cool project! Still very early stages though; in the article he says he&#x27;s &quot;only&quot; translated 6% of CVS to rust.<p>I wonder if corrode is already good enough for translating very low level numerical, i.e. imaging processing code...