Re: [Vala] Ref parameters to async methods

On Sat, 2011-07-23 at 15:22 +0800, Nor Jaidi Tuah wrote:
Is there any technical reason why
reference parameters are not supported for async methods?

My work around to this is simply to replace
  async void foo (ref X x)  // cannot compile

  async void foo (ClosureX cx)
where Closure is
  class ClosureX {
     X x;

But why can't the compiler do this for us?
I must be missing something.

Nor Jaidi Tuah

I assume that it is due to scoping:

async void foo (ref int i) {
  i = 0;

int j = 1;
foo.begin (ref j);

j is on the stack but foo will access it outside scope. You can use
pointers and take care about scoping/freeing as compiler cannot do it
for you:

async void foo (int *i) {
  *i = 0;

int j = 1;
foo.begin (&j, (obj, res) => {
    foo.end (res);
    assert (j == 0); // Ok - j still alive


Attachment: signature.asc
Description: This is a digitally signed message part

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