Re: [Vala] What is the right syntax for defining pointers or references or "aliases" in Vala ?



A very useful "feature" of Vala is to check the generated C code, especially
if you know enough about C to check what it's doing.  This way you can fix
some simple mistakes (mostly misunderstading of Vala) and even optimize your
code.
For instance, the sample you used would compile to (use the --save-temps
switch to keep the generated C code around):

void _vala_main (char** argv, int argv_length1) {
    char* _tmp0_;
    char* a;
    char* _tmp1_;
    char* b;
    _tmp0_ = _strdup0 ("hello");
    a = _tmp0_;
    _tmp1_ = _strdup0 (a);
    b = _tmp1_;
    fprintf (stdout, "a = %p\n", &a);
    fprintf (stdout, "b = %p\n", &b);
    _free0 (b);
    _free0 (a);
}

Which you can clearly see why they are different pointers, but we can also
see your mistake in the printf. Also if you change b to "string *" you can
clearly see that Vala no longer does a strdup, thus actually keeping the
same pointer values, not actually "copying" the strings.

*Alexandre Rosenfeld*


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