www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Question about Phobos library file ("ti_uint.d")

reply Marcio Faustino <m.faustino.remove gmail.com> writes:
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")?
Jan 13 2007
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
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;
 }

Because that would screw up if the difference between the two uints is greater than 2147483647. Stewart.
Jan 13 2007
parent Marcio Faustino <m.faustino.remove-this gmail.com> writes:
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.
Jan 13 2007