the bit[] type

Jonathan M Davis jmdavisProg at gmx.com
Fri Sep 24 02:57:46 PDT 2010


On Friday 24 September 2010 02:46:39 Emil Madsen wrote:
> Now I'm just curious, how does D represent a bool type as false and true, I
> take it that false is 0b00000000, is true anything but that? - or will the
> compiler make sure, that its always 0b11111111 or would it be 0b00000001?
> (as 0b11111111 would be -1 if signed) - is there a given standard for this,
> or is this up to the implementer of the compiler?

I believe that when you cast a bool to an integral type, false is *always* 0, 
and true is *always* 1. However, when casting an integral type *to* bool, any 
non-zero value is true. Whether the compiler bothers to always make the actual 
byte value of the bool 0x01 for true when casting to bool, I don't know. If you 
want to know for sure, I believe that you'll have to look at the generated 
assembly code.

- Jonathan M Davis


More information about the Digitalmars-d-announce mailing list