Brilliant !!!

Thanks a lot Alexandre, this is exactly the idea I was looking for.

- Mystery solveed !

- By simply looking at the C code (using  the --save-temps option), I
can see exactly what is going on under the hood and how references are
managed by Vala.

This also underlines that Vala is (among other things)  a smart C code
generator.

Super !
Thank you very much.




On Tue, Jun 21, 2011 at 2:04 AM, Alexandre Rosenfeld
<[email protected]> wrote:
> 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
> 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
>
>
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to