Bools reloaded

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Sat Mar 4 02:49:48 PST 2006


Oskar Linde wrote:
> Ivan Senji wrote:
> 
> 
>>Oskar Linde wrote:
>>
>>>&& and || controls the program flow.
>>
>>If's and while's containing them control program flow (or I didn't get
>>something right?)
> 
> 
> They control program flow by themselves too:
> 
> my_if() && (my_then(),1) || my_else(); 
> 
> Is equivalent to:
> 
> if (my_if())
>         my_then();
> else
>         my_else();
> 

Cool, I am never going to use if,then,else again ;)
This is so much cooler :)

> 
>>>&,|,~,^ are real operators that also maps directly onto machine
>>>instructions on most cpu architectures.
>>
>>Sure they are, and I use them all the time on ints.
>>
>>
>>>Their meaning would be well defined
>>>for bools.
>>
>>Not really:
>>bool a = //somehow 2
>>bool b = //somehow 4
>>a && b == true && true == true
>>a & b == 0x0010 & 0x0100 == 0x0000 == false,
>>
>>I mean they would work but only if true == always 1 and false == always 0.
> 
> 
> We all seem to be talking about different kinds of bool :). 

That is true.

> 
> [snip]
> 
> 
>>In the paragraf you replyed to I was just trying to say that having &,|
>>and ^ for bools only has meaning f they are strict logic bools and not
>>numeric.
> 
> 
> I see. I was talking about logical bools. Btw, the current bool (and C99
> _Bool, C++ bool) is defined to be either 1 or 0. Without sidestepping the
> type system there is no way to make a bool take any other value. This means
> that both numeric operators and bitwise operator are well defined. A bool
> can never somehow be 2 or somehow be 4. Assigning x to a bool makes an
> implicit (x!=0). Another numeric boolean representation where the least
> significant bit defines the truth state would also work with bit
> operations.

I did some teseting and it seems to be true. Then my only objection 
would be if and while taking non boolean arguments, or put differently 
implicit conversions from bool. But I'm going to stop complaining now 
and learn to continue to live with how it is now...


> 
> The bool you seem to be talking about is one where any numeric value != 0
> would represent true?
> 

Not really, I'm talking about an i'dont-care-what-it-is bool. :)



More information about the Digitalmars-d-announce mailing list