int opEquals(Object), and other legacy ints

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Jul 28 18:30:51 PDT 2006


kris wrote:
> Walter Bright wrote:
>> Stewart Gordon wrote:
>>> But if the function only tries to return 0 or 1 anyway, then what 
>>> difference does it make?  At the moment, I can't think of an example 
>>> of equality testing that can be made more efficient by being allowed 
>>> to return a value other than 0 or 1.
>>
>>
>> I can. (a == b), where a and b are ints, can be implemented as (a - 
>> b), and the result is int 0 for equality, int !=0 for inequality.
> 
> 
> So, why not treat false as 0, and true as not 0?  That way, it works 
> just the same as the "int" version does (and comparing/testing against 
> zero doesn't hit the address-bus). Yes, I can see some potential for 
> concern there; but is there anything insurmountable?

Then what would happen if a and b differ by, say, 256? Remember, an int 
is 4 bytes, a bool is only 1.



More information about the Digitalmars-d-bugs mailing list