3 ms·
I've tried to do that with my translator: https://gitlab.com/citrus-rs/citrus#readme https://gitlab.com/citrus-rs/citrus#readme Refactoring C to Rust code is h
by pornel 8y ago
I've tried to do that with my translator: https://gitlab.com/citrus-rs/citrus#readme https://gitlab.com/citrus-rs/citrus#readme
Refactoring C to Rust code is hard. It's not enough to derive bits of information function by function. Often you need to re-architect the whole approach, which is a Sufficiently Smart Compiler problem. Until I've tried it I did not fully realize just how much C uses pointers. Pointer soup is everywhere (and hardly any explicit lengths anywhere).
In C's type system the concept of ownership doesn't exist. From that angle it's "dynamically typed". Converting "any pointer can have any ownership, it's implicit from usage" to Rust's "all ownership is statically known" is as hard as converting JavaScript's use of types to a statically-typed language.
- vanderZwan 8y agoWouldn't it be simpler to do a C-to-Rust translator that produces Rust code that does not actually have to compile? Basically one-to-one but with errors in Rust because it's unsafe, and then let the programmers deal with the error codes. That still sounds like a valuable tool since it would take some parts of the boilerplate out of the equation.