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.

How to translate a large C project to Rust

158 pointsby vmbrasseurover 8 years ago

2 comments

duneroadrunnerover 8 years ago
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 未加载
drewm1980over 8 years ago
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...