[Issue 2931] New: Initialization struct with array from another struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 3 16:12:50 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2931

           Summary: Initialization struct with array from another struct
           Product: D
           Version: 1.042
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: mihail.zenkov at gmail.com


This example work fine:

import std.stdio: writefln;

struct D2 {
        double val[2];
}

void main() {

D2 p = { 1 };
double zoom = 2;
double move = 3;
double scale = 4;

writefln("p.val[0]=", p.val[0]);
writefln("p.val[1]=", p.val[1]);
writefln("zoom=", zoom);
writefln("move=", move);
writefln("scale=", scale);
}

and return:

p.val[0]=1
p.val[1]=1
zoom=2
move=3
scale=4

But if i try same in struct:

import std.stdio: writefln;

struct D2 {
        double val[2];
}

struct view {
        D2 p = { 1 };
        double zoom = 2;
        double move = 3;
        double scale = 4;
}

void main() {
        view v;
        writefln("p.val[0]=", v.p.val[0]);
        writefln("p.val[1]=", v.p.val[1]);
        writefln("zoom=", v.zoom);
        writefln("move=", v.move);
        writefln("scale=", v.scale);
}

i have:

p.val[0]=1
p.val[1]=nan
zoom=nan
move=2
scale=3


-- 



More information about the Digitalmars-d-bugs mailing list