[Vala] initializing structures



Just an observation -- not sure what is supposed to work or not ....

using GLib;

public struct mystruct {
    public string test1;
    public int test2;
}

void main (string[] args)
{

    /* the following code works fine */
    mystruct my_b = {"this is a test", 10};
    debug("%s, %i", my_b.test1, my_b.test2);

    /* does not compile */
    mystruct[] my_a = {
        {"this is a test", 10};
    };

    /* works */
    mystruct[] my_a = new mystruct[10];

    /* the following code does not compile */
    my_a[0] = {"this is a test", 10};

    /* the following works */
    my_a[0].test1 = "this is a test";
    my_a[0].test2 = 10;

    debug("%s, %i", my_a[0].test1, my_a[0].test2);
}




-- 
=======================
Cliff Brake
http://bec-systems.com



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