3 ms·
Is it possible to translate C into (unsafe) Rust while maintaining both human readability and link-level compatibility?
by amelius 6y ago
Is it possible to translate C into (unsafe) Rust while maintaining both human readability and link-level compatibility?
- pornel 6y agoI've attempted to implement this: https://lib.rs/citrus https://lib.rs/citrus And my conclusion is: No. • Rust deliberately makes unsafe syntax ugly and noisy to steer users towards the good parts. • C idioms are very different from Rust, and much harder to translate to "nice" Rust than it seems (e.g. getting rid of linked lists, or translating `goto cleanup` to RAII, pointer arithmetic to iterators quickly runs out of trivial cases and becomes a Sufficiently Smart Compiler problem). There's https://c2rust.com https://c2rust.com that at least preserves semantics accurately.
- dnautics 6y agothis is an evolving, and first-class capability of zig (you can run it now, the issue isn't closed because it's an epic) https://github.com/ziglang/zig/issues/2457 https://github.com/ziglang/zig/issues/2457
- MrRadar 6y agoHave you considered D's "Better C" mode? https://dlang.org/spec/betterc.html https://dlang.org/spec/betterc.html
- dmytrish 6y agoThere is also https://github.com/jameysharp/corrode https://github.com/jameysharp/corrode I have not used it, but I doubt it's possible to translate C into idiomatic Rust mechanically.