'int' is enough for 'length' to migrate code from x86 to x64

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 21 07:47:59 PST 2014


On Fri, Nov 21, 2014 at 03:36:01PM +0000, Don via Digitalmars-d wrote:
[...]
> Suppose  D had a type 'natint', which could hold natural numbers in
> the range 0..uint.max.  Sounds like 'uint', right? People make the
> mistake of thinking that is what uint is. But it is not.
> 
> How would natint behave, in the type system?
> 
> typeof (natint - natint)  ==  int     NOT natint  !!!

Wrong. (uint.max - 0) == uint.max, which is of type uint. If you
interpret it as int, you get a negative number, which is wrong. So your
proposal breaks uint in even worse ways, in that now subtracting a
smaller number from a larger number may overflow, whereas it wouldn't
before. So that fixes nothing, you're just shifting the problem
somewhere else.


T

-- 
Too many people have open minds but closed eyes.


More information about the Digitalmars-d mailing list