Re: [Vala] How to pass items of an array as out parameters?



Jürg confirms this is a bug.
So I entered a new one in bugzilla:

https://bugzilla.gnome.org/show_bug.cgi?id=609388


On Tue, Feb 9, 2010 at 2:17 AM, Sandino Flores Moreno <tigrux gmail com> wrote:
In my program, I need to initialize variables that are items of an array.
It's a situation that can be roughly simplified to this:

[test.vala]

void modify(out int n) {
       n = 5;
}

void main() {
       int[] a = new int[3];
       for(int i=0; i<a.length; i++)
               modify(out a[i]);
}

[/test.vala]

However, I get this error:

$ valac test.vala
test.vala:8.10-8.17: error: ref and out method arguments can only be
used with fields, parameters, and local variables
               modify(out a[i]);



More specifically, I had this code that is valid in C:

   OMX_BUFFERHEADERTYPE *inBufferAudioDec[2];
   for(i=0; i<2; i++) {
       err = OMX_AllocateBuffer(audiodechandle, &inBufferAudioDec[i],
0, NULL, buffer_in_size);
       if (err != OMX_ErrorNone)
           exit(1);
   }

That is translated to Vala as shown:

   Omx.BufferHeader[] inBufferAudioDec = new Omx.BufferHeader[2];
   for(i=0; i<2; i++) {
       err = audiodechandle.allocate_buffer(out inBufferAudioDec[i],
0, null, buffer_in_size);
       if (err != Omx.Error.None)
           Posix.exit(1);
   }

But, Vala fails with the error specified in the canonical example.

So, how should I pass items of an array as out parameters of a method
or function?




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