Sorry, to avoid copying it should be like this:
----
const string constar[] = {"first", "second", "third"};

void main () {
    foreach(unowned string s in constar)
        print("s: %ss\n", s);
}
----



Am Mittwoch, den 21.12.2011, 11:38 +0100 schrieb JM:
> For example, you can do it like this:
> ----
> const string constar[] = {"first", "second", "third"};
> 
> void main () {
>     foreach(string s in constar)
>         print("s: %ss\n", s);
> }
> ----
> 
> 
> 
> Am Mittwoch, den 21.12.2011, 16:34 +0800 schrieb PCMan:
> > I C language, I can do this:
> > const char* strs[] = {
> >   "string1",
> >   "string2",
> >   "string3",
> >   NULL
> > };
> > 
> > In Vala, I cannot find a way to do the same.
> > Defining a string[] will cause copy of every constant string.
> > If I use unowned, like this:
> > 
> > unowned string strs[] = {
> >   ...
> > };
> > 
> > This did not generate the same result.
> > Every element of the string array gets copied.
> > 
> > So, If I need an array containing constant unowned strings, how to define
> > it in Vala?
> > Besides, in C language, we can write "const char* const *".
> > In Vala, I cannot find equivalent stuff.
> > Help is needed.
> > 
> > Thanks a lot!
> > _______________________________________________
> > vala-list mailing list
> > [email protected]
> > http://mail.gnome.org/mailman/listinfo/vala-list
> 
> 
> _______________________________________________
> vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list


_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to