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

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 21 17:57:05 PST 2014


On 11/21/14 1:55 PM, Marco Leise wrote:
> Am Wed, 19 Nov 2014 18:20:24 +0000
> schrieb "Marc Schütz" <schuetzm at gmx.net>:
>
>> I'd say length being unsigned is fine. The real mistake is that
>> the difference between two unsigned values isn't signed, which
>> would be the most "correct" behaviour.
>
> Now take my position where I explicitly write code relying
> on the fact that `bigger - smaller` yields correct results.
>
> uint bigger = uint.max;
> uint smaller = 2;
> if (bigger > smaller)
> {
>      auto added = bigger - smaller;
>      // Now 'added' is an int with the value -3 !
> }
> else
> {
>      auto removed = smaller - bigger;
> }

Interesting insight. Thanks for the many analytical examples you're 
giving in this thread. -- Andrei



More information about the Digitalmars-d mailing list