[dmd-beta] Struct Comparision WTF: Is the new or old behavior right?

kenji hara k.hara.pg at gmail.com
Sat Dec 10 00:51:31 PST 2011


Current dmd front-end does not generate member-wise comparison code
for floating point members.
It is already filed as issue 3789 (and I've posted a pull request
dmd/#387 to fix it).

So 64bit mode result is *accidentally* correct.

Kenji Hara

2011/12/10 Walter Bright <walter at digitalmars.com>:
>
>
> On 12/9/2011 10:36 PM, David Simcha wrote:
>>
>> Using DMD 2.057 beta:
>>
>> // test2.d:
>> import std.stdio;
>>
>> struct S {
>>    double d;  // NaN
>> }
>>
>> void main() {
>>    S s;
>>    writeln(s == S.init);
>> }
>>
>> $ dmd test2.d -m32
>> $ ./test2
>> true
>> $ dmd test2.d -m64
>> $ ./test2
>> false
>>
>> Somehow I think it's a bad idea to have the result of this comparison
>> change depending on whether you're compiling in 32- or 64-bit mode.  I just
>> spent a few hours debugging Plot2kill because this behavior changed between
>> releases in 64-bit mode, and I was comparing font structs to their .init
>> values to determine whether they had already been initialized.  Everything
>> worked in 32-bit mode but failed in 64-bit mode.  In 64-bit mode it looked
>> like the structs had already been initialized (e.g. titleFont == Font.init
>> is false) so they never got initialized.  Needless to say, GTK does weird
>> things when you pass in a NaN as a font size.
>>
>
> The 32 bit code is wrong (please file a bug report). Comparisons should
> always yield false if one or both operands is a nan.
>
> _______________________________________________
> dmd-beta mailing list
> dmd-beta at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-beta


More information about the dmd-beta mailing list