Re:mrustc: In-progress alternative Rust compiler (to C)
by tedunangst on Sunday February 28, 2021 @05:26PM
(#26297696)
Pretty sure rust wraps on overflow, not saturates, but it's not hard to get that behavior from most C compilers if desired.
Re:mrustc: In-progress alternative Rust compiler (to C)
by pornel on Sunday February 28, 2021 @06:27PM
(#26298115)
float to integer saturates in Rust. `99999.0 as u8` gives 255. `(char)99999.0` is UB in C and LLVM. Rust had to add explicit clamping code to float casts, because LLVM compiled nasal demons otherwise: https://github.com/rust-lang/rust/issues/10184
Rust also has different aliasing rules. Stricter than C for references, but more relaxed than C for raw pointers.
Re:mrustc: In-progress alternative Rust compiler (to C)
by tedunangst on Sunday February 28, 2021 @09:36PM
(#26299133)
Clamping floats is interesting, but seems pretty niche.
Re:mrustc: In-progress alternative Rust compiler (to C)
by tedunangst on Sunday February 28, 2021 @09:38PM
(#26299148)
Would have been nice to provide notice of your edits.
Re:mrustc: In-progress alternative Rust compiler (to C)
by gpm on Sunday February 28, 2021 @09:54PM
(#26299234)
I'm not sure if I edited at all, if I did edit it was within a minute or two of my original post.
Edit: Now that I am coming back and reading this though I am going to make an edit, and like normal for substantive edits I'm going to mark it clearly...
Edit2: Or I can't edit, so let's put it here:
A better example than any of the above might be infinite loops, `while (true) {}` (or any similar loop without side effects) is undefined behavior in C, it's defined behavior in rust.
Re:mrustc: In-progress alternative Rust compiler (to C)
by tedunangst on Sunday February 28, 2021 @11:24PM
(#26299738)
Unfortunate timing.
Float integer conversions (overflows are defined to saturate in rust, are undefined behavior in C).
Maybe things like how pointer casts are treated in correct (but unsafe) rust vs C. Or similarly in transmute. Generally it wouldn't surprise me if rust was standardizing a memory model that was subtly different from C.
I'm sure the list goes on, but "that sort of thing".