Creating array of structs being used in C interface

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 27 06:27:54 PST 2016


On Sunday, 27 November 2016 at 14:12:31 UTC, Timoses wrote:
> If I change the union's variable type to "int" (or any other) 
> it compiles just fine. So the problem seems to be the "double" 
> value.

That's because int is zero initialized by default and thus 
doesn't need anything more than a call to zero memory function, 
and double isn't (it is NaN), so it gets an initializer data 
blob. If you make it = 0 it might work, but even then, the 
compiler may want to reference the initializer just because 
there's a non-default init value!

> Should I still report it as a bug here:

It isn't a bug, this is working as designed [1]. Making it skip 
the initializer with =void or =0 explicit init values is a valid 
enhancement request though.

1: search for "default" on this page 
http://dlang.org/spec/struct.html#static_struct_init


More information about the Digitalmars-d-learn mailing list