DMD 0.148 release

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Feb 28 03:03:05 PST 2006


Walter Bright skrev:
> "Tom" <Tom_member at pathlink.com> wrote in message 
> news:du049t$2uv2$1 at digitaldaemon.com...
>> Yes, PLEASE, WHY?? Just ONE argument against pure bools, only one and I 
>> shut my
>> mouth forever!
> 
> One should be very careful about stepping away from C's implicit promotion 
> rules for a language that aims to be a successor to C. C absolutely *buried* 
> Pascal.

I agree. I also find while(5) to be perfectly acceptable. But the 
problem with placing bool in the integer promotion chain is that it has 
a semantic difference to the other integer types.

- cast from a larger type to bool is defined as x != 0, rater than the 
analogue of (x&1) for the other integer types.

This gives bool slightly different arithmetic properties as I mentioned 
in a very lengthy post in another place in this thread.
(news://news.digitalmars.com:119/dtv65q$1ps2$1@digitaldaemon.com)

One such property is the asymmetry: bool never overflows but does 
underflow. (a++ sets a to true, while a-- flips a's truth value).

Another reason not to place bool among the other integer types is that 
many people expect a bool to be semantically different from integer types.

For instance, if you know about boolean algebra, you would expect a+b to 
be evaluated as a or b... And it is -- almost. The integer promotion 
unfortunately makes comparisons of truth values shaky (assume a,b boolean):

(a+b == true) // here, + becomes xor!

vs:

bool x = a+b; // here, + behaves as or

If bools where removed from the integer promotion chain, the problem 
with "== true" would go away. Forever. :)

/Oskar



More information about the Digitalmars-d-announce mailing list