News for hackers. Stuff that matters.
Re:Comparative unsafety by thaumasiotes on Friday April 09, 2021 @11:09AM (#26751476)
I actually find ~0 more intuitive. u32::MAX makes me think the relevant concept is "a really big number"; ~0 makes me think the relevant concept is "a bunch of bits that are all 1s".
Re:Comparative unsafety by ChrisSD on Friday April 09, 2021 @11:20AM (#26751631)
Fair enough. But tbh I'm not sure it really matters in this context. It's just a constant that means "ignore this parameter". Whether it's "a really big number" or "a bunch of bits that are all 1s" is incidental.

Btw, you can directly express "all ones" in Rust as:

    0b_1111_1111_1111_1111_1111_1111_1111_1111
Though it's somewhat less succinct. ;)

EDIT: Added more ones, thanks adwn!

Re:Comparative unsafety by adwn on Friday April 09, 2021 @11:26AM (#26751718)
> 0b1111_1111_1111_1111

That's just 16 bits and will result in the value 65535, not -1.

Re:Comparative unsafety by ChrisSD on Friday April 09, 2021 @11:29AM (#26751772)
Ha, yes you're right. I'm on my phone and got tired of writing ones. I'll edit when I'm next at my laptop.