Shouldn't bool be initialized to 0xFF ?

Lionello Lunesu lio at lunesu.remove.com
Fri Aug 18 00:20:02 PDT 2006


>> This I don't get. How's having a default of false better than having a 
>> default of true?
> 
> I can see why this might not be obvious if you do not much of a 
> background with C style languages. In most C style languages (C, C++, 
> Java and D) pretty much anything is 'true' if it is non-zero because 
> 'truth' can be determined by simply testing for inequality with the 
> constant 0. Thus the only default initializer which works the same for 
> "pretty much anything" is a zero bit pattern. I think it is impossible 
> to stress enough how ingrained this reality becomes. The best example of 
> exactly how ingrained it is would be my implicit assumption that anyone 
> else would see the folly of a default value evaluating true.

I'm coming from C/C++ myself. In C/C++ you always have to initialize 
your variables, so the language has no preference for either true or 
false. Are you saying that you name your variables and flags such that 
"false" is the default? That seems like strange to me. For program 
options, for example, it would mean that you choose names that are "not 
true" (options that are not selected) as the default. Seems exactly the 
wrong way around. Not to mention the fact that you can end up with 
variables called "NotShowingSizes = false;" and "if (!NotShowingSizes) 
..."  :S

>>     bit is gone, and bool is similar to C++'s bool. bool.sizeof==1, 
>> and a bool[32] needs 32 bytes.
> 
> Do you know why it was eliminated? Or perhaps have some idea of when? Or 
> even a general spot to start looking in posts to find out why myself?

I think because of the problems with bit[] and the fact that you could 
not take a pointer to it. Check the change log 
http://www.digitalmars.com/d/changelog.html (I would check it for you, 
but it seems I can't access it at the moment?)

L.



More information about the Digitalmars-d mailing list