4 ms·
IMO everyone gets it wrong. In a CPU instruction set, signed and unsigned are operations, not values, so why not extend that to low level languages? An int32 is
by mypalmike 4y ago
IMO everyone gets it wrong. In a CPU instruction set, signed and unsigned are operations, not values, so why not extend that to low level languages? An int32 is neither signed nor unsigned. When you compare them, you choose signed or unsigned comparison.
Rust gets points in my book for being more explicit and avoiding arbitrary promotion rules. Plus the standard lib has specific functions for things like add with overflow which reflect what the CPU flags are doing.
- WalterBright 4y ago> When you compare them, you choose signed or unsigned comparison. True. I've done a lot of assembler programming. Getting the right jxx instruction after a compare was a prolific source of bugs. I've had a lot fewer bugs with signed types :-) > Plus the standard lib has specific functions for things like add with overflow which reflect what the CPU flags are doing. D does, too: https://dlang.org/phobos/core_checkedint.html https://dlang.org/phobos/core_checkedint.html along with integer types that automatically check for overflow: https://dlang.org/phobos/std_checkedint.html https://dlang.org/phobos/std_checkedint.html
- mypalmike 4y agoNice. I haven't really looked into D before but maybe I'll spend some time with it soon.
- IgorPartola 4y agoSo same would have to work for signed vs unsigned addition, subtraction, bit shifts, powers, etc., right?
- mypalmike 4y agoYes.