[Vala] Question about foreach and pointers.



Hi folks.

I have struct from external C library, I wrote vapi:

[CCode ...]
public struct sameitem{
 ....
}

[CCode (cheader_filename = "makeflop.h")]
public struct listinfo {
  ...
  [CCode (array_length_cname = "num", array_length_type = "int")]
  public weak sameitem[] list;
  ...
}

I create GTK3 ListStore model with pointer data:

new ListStore(8, typeof(void*) ....)

And fill model:

(I have listinfo)
listinfo info;

foreach(listinfo i in info.list){
  ii_list.append (out iter);
  ii_list.set(iter, 0, &i)
}

But pointer on "&i" is not pointer to info.list[iterator].
Vala create object "listinfo i" and copy struct in to it:

for(..){
 listinfo i=info.list[iteration];
 ii_list.append (out iter);
 ii_list.set(iter, 0, &i)
}

Result: I have array bad pointers. Pointers to local listinfo items.

How I can make array to info.list[iterators] if I want use "foreach"?

Example, I write valid code using "for":

 for(j=0; j<info.list.length; j++){
    ii_list.append (out iter);
    ii_list.set(iter, 0, &l.ii[j] /<cut>)
}

-- 
Sorry for my english
Leonid Myravjev



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