how to initialize nested struct elegantly?

2018-12-12 Thread elvisxzhou via Digitalmars-d-learn
import std.stdio; struct AA { int i; char c; double d; string s; float f; } struct BB { float f; AA[2] a; } void print(BB* bb) { writefln("bb.a[0].i=%d bb.f=%f", bb.a[0].i, bb.f); } void main() { //dlang AA aa = { i:1010, f:0.1f };

Re: how to initialize nested struct elegantly?

2018-12-12 Thread elvisxzhou via Digitalmars-d-learn
On Wednesday, 12 December 2018 at 09:49:58 UTC, elvisxzhou wrote: import std.stdio; struct AA { int i; char c; double d; string s; float f; } struct BB { float f; AA[2] a; } void print(BB* bb) { writefln("bb.a[0].i=%d bb.f=%f", bb.a[0].i, bb.f); } void main() {

Re: how to initialize nested struct elegantly?

2018-12-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/12/18 4:49 AM, elvisxzhou wrote: dlang version has two unnecessary symbols aa and bb, which is ugly compare to c99 one. Well, this works: BB bb = { f : 0.2f, a : [ {i:1010, f:0.1f}, // note the nested field name syntax {i:1020, f:0.2f}