bool <=> int. WTF. (DIP0015)
lithium iodate
whatdoiknow at doesntexist.net
Fri Jul 5 21:45:00 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.
Bug because it is inefficient or incorrect?
To the best of my knowledge C does only mandate that _Bool must
be able to store 0 and 1, and imposes no requirements on how
other representations have to be treated. GCC treats _Bool as
having 2 valid representations and 254 trap representations, so x
== 1, x & 1 and x > 0 are all necessarily equivalent given this
assumption. Not sure about Clang, in my quick test it always only
checked the least significant bit.
Does D really not have more specific requirements for bool? (Does
D even allow anything to have trap representations? There doesn't
really seem to be any info on that)
More information about the Digitalmars-d
mailing list