[Vala] Unowned references to structures

If I do this:

class Foo { public Bar bar; }
class Bar { public int a; }

static void t(Foo foo)
        unowned Bar bar = foo.bar;

...then bar becomes, as expected, an alias for foo.bar.

However, if I change the classes to structures, then the 'unowned' is
accepted silently but now bar becomes a *copy* of foo.bar.

After a bit of thought I can see why this happens, as structures are
strictly pass-by-reference, but it nevertheless came as a surprise.
Given that the two cases look very similar but have decidedly different
semantics, is there any chance of getting an error if people use
'unowned' with a non-value type?

Also, before I give up and use pointers, is there any way of getting an
alias to a structure member?

┌─── 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]