[OT] The Usual Arithmetic Confusions

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 4 21:27:44 UTC 2022


On Fri, Feb 04, 2022 at 08:50:35PM +0000, Mark via Digitalmars-d wrote:
> On Friday, 4 February 2022 at 04:28:37 UTC, Walter Bright wrote:
> > There's really no fix for that other than making the effort to
> > understand 2s-complement. Some noble attempts:
> > 
> > Java: disallowed all unsigned types. Wound up having to add that
> > back in as a hack.
> 
> How many people actually use (and need) unsigned integers?

I do. They are very useful in APIs where I expect only positive values.
Marking the parameter type as uint makes it clear exactly what's
expected, instead of using circumlocutions like taking int with an
in-contract that x>=0.  Also, when you're dealing with bitmasks, you
WANT unsigned types. Using signed types for that will cause values to
get munged by unwanted sign extensions, and in general just cause grief
and needless complexity where an unsigned type would be completely
straightforward.

Also, for a systems programming language unsigned types are necessary,
because they are a closer reflection of the reality at the hardware
level.


> If 99% of users don't need them, that's a good case for relegating
> them to a library type.  This wasn't possible in Java because it
> doesn't support operator overloading, without which dealing with such
> types would have been quite annoying.

Needing a library type for manipulating bitmasks would make D an utter
joke of a systems programming language.


T

-- 
First Rule of History: History doesn't repeat itself -- historians merely repeat each other.


More information about the Digitalmars-d mailing list