struct members not default initialized?

Ali Cehreli acehreli at yahoo.com
Mon Dec 7 17:38:46 PST 2009


bearophile Wrote:

> This prints 42 0.000000 with the latest dmd2 and 42 nan with an older dmd1. It can be a bug:

It prints garbage here with 2.037. :/

As I've responded to my own post :), I think the initialization is meant only for static objects.

> 
> import std.c.stdio: printf;
> 
> struct S {
>     int i;
>     double d;
> }
> 
> void main() {
>     S s = { 42 };
>     printf("%d %f\n", s.i, s.d);
> }
> 
> Bye,
> bearophile

Ali



More information about the Digitalmars-d-learn mailing list