4 ms·
"it compiles it to unsafe Rust with all the weaknesses of the C code" Isn't that the idea? Sure, it makes it into essentially a blob of uneditable code. But i
by jeffdavis 7y ago
"it compiles it to unsafe Rust with all the weaknesses of the C code"
Isn't that the idea?
Sure, it makes it into essentially a blob of uneditable code. But it allows you to integrate it with rust code and build the whole thing together.
- setr 7y agoNot when it's being pitched by gp as an alternative to rewriting such that the rewrite is the primary code. This particular scenario is one where an opaque blob is not at all the goal, and thus c2rust is not a valid strategy
- Animats 7y agoIt seems that part of the goal of c2rust was to retain the C memory layout in memory. If that's not required, C arrays can be translated to Rust arrays. Except for some corner cases involving casts and pointer arithmetic, that should work, and generate much cleaner output code. You can detect those, at least. For pointer arithmetic, do the pointer arithmetic and convert it to a subscript before indexing. Then you have bounds checks. This is a classic problem with computer language conversion - you lose the idioms of both the input language and the output language in translation.
- microcolonel 7y ago> it makes it into essentially a blob of uneditable code. No, it doesn't. It retains comments, the names of variables, and most of the structure of the code. You're meant to be able to factor the unsafe behaviours out incrementally from there (and there are a lot of bundled and associated tools meant for exactly that). I ran an example through c2rust the other day and rustc told me immediately that I had functions that didn't need to be marked unsafe. switch statements are probably the thing that suffers most with c2rust, though I think there's a tool for that.