'int' is enough for 'length' to migrate code from x86 to x64
Matthias Bentrup via Digitalmars-d
digitalmars-d at puremagic.com
Thu Nov 20 05:56:16 PST 2014
On Thursday, 20 November 2014 at 13:26:23 UTC, FrankLike wrote:
>
>>> auto x = foo();
>>> auto y = bar();
>>> auto z = baz();
>>>
>>> if (x - y > z) { ... }
>>>
>>>
>>> This might be a bug, if one of these functions returns an
>>> unsigned
>>> type. Good luck finding that. Note that if all functions
>>> return
>>> unsigned, there isn't even any signed-unsigned mismatch.
>>>
>>> I believe the correct statement, is "With only a bit of care
>>> one can use
>>> D's unsigned types for positive numbers and believe that
>>> one's code is
>>> correct, even though it contains subtle bugs."
>>
>> Well I'm sorry but I quite disagree. -- Andrei
>
> This might be a bug.
>
> 'Length' always needs to compare sizes. 'Width' and 'Height'
> like it.
>
> ************************ dfl/drawing.d line:185 -218
> **************************
>
> ///
> Size opAdd(Size sz)
> {
> Size result;
> result.width = width + sz.width;
> result.height = height + sz.height;
> return result;
> }
>
>
> ///
> Size opSub(Size sz)
> {
> Size result;
> result.width = width - sz.width;
> result.height = height - sz.height;
> return result;
> }
>
>
> ///
> void opAddAssign(Size sz)
> {
> width += sz.width;
> height += sz.height;
> }
>
>
> ///
> void opSubAssign(Size sz)
> {
> width -= sz.width;
> height -= sz.height;
> }
> ***********************end*************************
> if the type of width and height are size_t,then their values
> will be error.
>
>
> small test:
> -----------------------
> import std.stdio;
>
> void main()
> {
> size_t width = 10;
> size_t height = 20;
> writeln("before width is ",width," ,height is ",height);
> height -= 1;
> width -= height;
> writeln("after width is ",width," ,height is ",height);
> }
> ----------
> "after width is " ERROR.
I get "after width is 18446744073709551607 ,height is 19", which
looks mathematically correct to me.
More information about the Digitalmars-d
mailing list