3 ms·
Has anyone experimented with a C-to-Rust translator? Google wrote a C-to-Go translator to aid their conversion of the Go compiler from C to Go. Carol Nichols g
by cpeterso 10y ago
Has anyone experimented with a C-to-Rust translator?
Google wrote a C-to-Go translator to aid their conversion of the Go compiler from C to Go. Carol Nichols gave a talk about her function-by-function, by-hand rewrite of the Zopfli compression library from C to Rust. I wonder how much of that could be automated, even if most of the resulting Rust code is in unsafe blocks.
Carol's slides:
https://github.com/carols10cents/rust-out-your-c-talk https://github.com/carols10cents/rust-out-your-c-talk
- legulere 10y agoI guess the output would be very ugly as the C semantics are probably ugly to reproduce in rust. For instance arithmetic with unsigned types in C is defined to be wrapping, so you would need e.g. calls to wrapping_add() instead of + all the time.
- pornel 10y agoI'd be OK with a shallow syntactic translator that only does the first laborious step of the conversion, without trying to preserve too much semantics. Rust with exact C semantics isn't going to be better than C, so I'd prefer readable code that is easier to read & refactor. I've converted a few utilities from C to Rust. Rewriting `void foo(int a)` to `fn foo(a:int)` is boring menial job. Only the next step of replacing C's pile'o'pointers with Rust idioms is fun.