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

David Simcha dsimcha at gmail.com
Fri Dec 9 22:36:08 PST 2011

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
$ dmd test2.d -m64
$ ./test2

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.

More information about the dmd-beta mailing list