Thread overview
Question about Phobos library file ("ti_uint.d")
Jan 13, 2007
Marcio Faustino
Jan 13, 2007
Stewart Gordon
Jan 13, 2007
Marcio Faustino
January 13, 2007
Hi everyone,

Why does the method compare of the class TypeInfo_k (in file "src/phobos/std/typeinfo/ti_uint.d") isn't simply:

int compare(void *p1, void *p2) {
    return *cast(uint*) p1 - *cast(uint*) p2;
}

as the same method of the class TypeInfo_h (in file
"src/phobos/std/typeinfo/ti_ubyte.d")?
January 13, 2007
Marcio Faustino wrote:
> Hi everyone,
> 
> Why does the method compare of the class TypeInfo_k (in file
> "src/phobos/std/typeinfo/ti_uint.d") isn't simply:
> 
> int compare(void *p1, void *p2) {
>     return *cast(uint*) p1 - *cast(uint*) p2;
> }
<snip>

Because that would screw up if the difference between the two uints is greater than 2147483647.

Stewart.
January 13, 2007
Stewart Gordon wrote:
> Because that would screw up if the difference between the two uints is greater than 2147483647.
>
> Stewart.

Right, because of the int.max limit. Thanks.