Union copy

"Luís "Luís
Mon Oct 21 19:47:33 PDT 2013


Consider the following on a 32-bit system:

     union Foo
     {
         struct
         {
             void* v;
             int i;
         }

         double d;
     }

     static assert(Foo.sizeof == 8);

     void copy(Foo* a, Foo* b)
     {
         version(one)
         {
             a.v = b.v;
             a.i = b.i;
         }
         version(two)
         {
             a.d = b.d;
         }
     }

Is there a difference between version one and version two? I was 
getting erroneous copies with version two on Linux and Windows, 
while it worked fine on OS X. Does it make a difference if the 
double is a NaN?


More information about the Digitalmars-d mailing list