int opEquals(Object), and other legacy ints

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Tue Aug 1 13:09:44 PDT 2006


Walter Bright wrote:
> Bruno Medeiros wrote:
>> Well, let's think about the other way around then. Why should bool be 
>> constrained to 0 or 1? Why not, same as kris said, 0 would be false, 
>> and non zero would be true. Then we could have an opEquals or any 
>> function returning a bool instead of int, without penalty loss.
>>
>> The only shortcoming I see is that it would be slower to compare two 
>> bool /variables/:
>>    (b1 == b2)
>> that expression is currently just 1 instruction, a CMP, but without 
>> the 0,1 restriction it would be more (3, I think, have to check that). 
>> However, is that significantly worse? I think not. I think comparison 
>> between two bool _variables_ is likely very rare, and when it happens 
>> it is also probably not performance critical. (statistical references?)
>> Note: this would not affect at all comparisons between a bool variable 
>> and a bool literal. Like (b == true) or (b == false).
> 
> I think most programmers would find this to be very surprising behavior. 
> I know I would.

Surprising behavior? What surprising behavior, those are all 
implementation details, they have not a bearing on language/program 
behavior.

And how about the alternative of using the SETE instruction for bool 
restriction?, you haven't commented on that yet...

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-bugs mailing list