Comment

Comment by millstone

> It allows the programmer to express intent.

Can the programmer express the intent that this will not overflow? i.e. is it possible to coerce the Rust compiler to optimize (x*2)/2 to x? "Cheap hardware traps" cannot substitute for such a compile-time optimization.

> C seems pretty hopeless since there is no way to know whether or not the coder intended on overflow or not.

Well this doesn't matter: if signed arithmetic overflows the code is undefined, regardless of intent.

In practice comments can express intent, and unsigned arithmetic can with some finessing produce most codegen. Explicit operators would be a big improvement though.

parent millstone 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton