opEquals needs to return bool

Sean Kelly sean at invisibleduck.org
Fri May 16 14:16:32 PDT 2008


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Edward Diener:
> > IMO, even if it were so, one does not twist programming design for a
> > performance gain.
> In some situations bools are slower, for example you can try this small program:
> http://codepad.org/pD22tteK
> if at line 8 you replace:
> int is_valid, went_off_right_side;
> With a logically more correct:
> bool is_valid, went_off_right_side;
> The program runs slower (with DMD on my CPU about 4% slower).

In the original discussion, it came out that DMD doesn't generate optimal
code for returning bools in this fashion, apparently because Walter was
unaware of the relevant ASM instruction to speed this up.  It's hidden
somewhere in a rather long conversation in this NG from perhaps 2 years
ago.

> Bools are bytes, while ints are 4 bytes, so sometimes ints are managed faster.

So why not just make bool a 4-byte value?  Using an integer to represent a
boolean operation is just silly.


Sean



More information about the Digitalmars-d mailing list