bool <=> int. WTF. (DIP0015)

wjoe invalid at example.com
Fri Jul 5 16:48:40 UTC 2019


On Friday, 5 July 2019 at 09:04:26 UTC, Patrick Schluter wrote:
> On Friday, 5 July 2019 at 03:10:06 UTC, Exil wrote:
>> On Thursday, 4 July 2019 at 16:31:11 UTC, Patrick Schluter 
>> wrote:
>>> that's the issue. D's bool type follows exactly C (C has bool 
>>> since C99) and C++ way.
>>> bool b; will behave exactly like your bool b = void;
>>
>> It doesn't have the same behavior. Currently DMD's codegen is 
>> bad, sometimes it checks the entire byte value and other times 
>> it only checks the first bit. All C/C++ compilers I've used 
>> check the entire value, consistently.
>
> if the codegen does something like (x & 1) then it is indeed a 
> BUG and should be corrected.

No. If bool is really a 1 bit integer then this generated code is 
correct.

Since there are no 1 bit registers the compiler must use a bigger 
one for a 1 bit integer.
The resulting behavior when storing values > 1 into this int1 is 
akin to an integer overflow hence it's not a bug.


More information about the Digitalmars-d mailing list