2 ms·
The premise here must be that the translator (human) has the original C code. So answering questions like "is this an array" is as simple as reading the C code
by staticassertion 8y ago
The premise here must be that the translator (human) has the original C code. So answering questions like "is this an array" is as simple as reading the C code to determine that.
Allocating too much space or getting a subscript error seems preferable to unsafety, and something one can hammer out with oracle testing.
Actually, it would be cool if there were generated quickcheck-like oracle testcases alongside this so you could start your translation to safe rust and test along the way.
- Animats 8y agoSo answering questions like "is this an array" is as simple as reading the C code to determine that. If only. Here's the original function definition: void insertion_sort(int const n, int * const p) "p" is really an array. But C doesn't know that. Rust needs to know. Around 2010, I proposed an extension to C [1] in which you'd write that as void insertion_sort (int const n, int& p[n]) Instead of a pointer, you'd use a reference to an array. Same calling sequence - the compiler passes a pointer. But with enough info that the callee knows the array size. Rust needs that info to do its job. Somehow, you have to get that info into a C to Rust translator. [1] http://www.animats.com/papers/languages/safearraysforc43.pdf http://www.animats.com/papers/languages/safearraysforc43.pdf
- staticassertion 8y agoIt is as simple as the C code, whether that is simple or not.