[Vala] Structure initialisation syntax



What's the syntax to initialise an instance of a structure on the stack?

The obvious doesn't work:

struct Foo { int a; int b; int c; }
Foo foo = { b=2 };

The less obvious is accepted but generates broken code:

Foo foo = { b: 2 };

->

Test _tmp0_ = {0};
Test test;
_tmp0_.a = 2; /* initialises a, not b */
test = _tmp0_;

This *does* work:

Foo foo = new Foo() { b=2 };

...but this turns into:

Test _tmp0_ = {0};
Test _tmp1_ = {0};
Test test;
memset (&_tmp0_, 0, sizeof (Test));
_tmp0_.b = 2;
_tmp1_ = _tmp0_;
test = _tmp1_;

This (argh! two temporaries!) is obviously actually creating an inline
instance of Foo and assigning it to foo, which isn't a structure
initialiser. What's the right way of doing this?

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ "I have a mind like a steel trap. It's rusty and full of dead mice."
│ --- Anonymous, on rasfc

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]