<div>Now I&#39;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?<br>
</div><div><br></div><div>About the bit type, and the bitarray, if I&#39;m interresting in doing anything alike this, I&#39;m off to allocating an array of chars? - and bitwise accessing them, to change them?</div><div><br>
</div><div>And now another piece of curiousity, how did this align in memory, would the compiler couple up bit types, to fill out a byte? - and if so, in how large a scope would it do this? - current scope?</div><br><div class="gmail_quote">
On 23 September 2010 19:32, bearophile <span dir="ltr">&lt;<a href="mailto:bearophileHUGS@lycos.com">bearophileHUGS@lycos.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
jcc7:<br>
<div class="im"><br>
&gt; As you can see from the links to newsgroup threads at the bottom of the first<br>
&gt; page, the topic was discussed over many years. Perhaps the discussions have<br>
&gt; tapered off in recent years because the current approach is right.<br>
<br>
</div>It&#39;s an interesting read, thank you (I was present only at the tail of it).<br>
<br>
It&#39;s a good example of how even an &quot;obviously simple&quot; feature like a bool/bit type may hide complexities, design difficulties, requires engineering trade-offs, and in the end may produce something with some inevitable design defects.<br>

<br>
~bool is forbidden, but in DMD a bool is represented with 8 bits, so it has 255 ways to be true and 1 to be false. A boolean like this:<br>
<br>
bool b = void;<br>
<br>
May contain something different from 0 or 1, this may cause some surprise.<br>
<br>
In those discussions I have seen Walter against the usage of bool as return type for opEquals, because a cast(bool)some_int is equivalent to:<br>
n ? 1 : 0<br>
That requires some instructions, so it isn&#39;t fully efficient.<br>
<br>
In the pages (operatoroverloading.html and hash-map.html) about the D2 language I have seen different signatures for the struct opEquals, so I may add a little documentation bug report about it:<br>
int opEquals(ref const S s);<br>
const bool opEquals(ref const KeyType s);<br>
<br>
P. 258 of TDPL shows a struct opEquals that returns a bool, so I presume the efficiency considerations have left space for a more semantically clean implementation. Isn&#39;t DMD able to optimize away (when inlining is present) the slowdown caused by the n?1:0 ?<br>

<br>
Bye,<br>
<font color="#888888">bearophile<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>// Yours sincerely<br>// Emil &#39;Skeen&#39; Madsen<br>