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



All right , they might "behave like" pointers, but they are not mere
pointers, cf:


///
using Posix;

void main (string[] argv) {

    string a = "hello";
    string b = a;
    Posix.stdout.printf("a = %p\n", &a);
    Posix.stdout.printf("b = %p\n", &b);
}
///

Which yields:

a = 0x7fff5fbff890
b = 0x7fff5fbff880

Obviously two different addresses (pointer values).

Also changing b does not change a.

This is very confusing, from a C (or C++) point of view !

The Vala references, look more like Python (implicit) references than
like C (explicit) references.

Obviously, they are not ordinary C pointers as in :

///
char * a = "Hello";
char * b = a;
///

Serge.




On Mon, Jun 20, 2011 at 11:11 PM, Daniel Alonso <dani apanoia gmail com> wrote:
Please read the Vala Tutorial, specially the section "Datatypes" where
it explains which types in vala qualify as reference types and which
ones qualify as value types.

Reference types when an assignment without the "new" operator behave
as pointers.

El dilluns 20 de juny de 2011, Daniel Alonso <dani apanoia gmail com> ha escrit:
Hi, you have to use the "new" operator in order to create a new
instance of a class. Any assignment of a variable to an existing
instance is just a reference to the same instance.

Best regards.

El dilluns 20 de juny de 2011, Serge Hulne <serge hulne gmail com> ha escrit:
How can it be checked ?

Serge.


---------- Forwarded message ----------
From: tecywiz121 <tecywiz121 hotmail com>
Date: Mon, Jun 20, 2011 at 9:55 PM
Subject: Re: [Vala] What is the right syntax for defining pointers or
references or "aliases" in Vala ?
To: Serge Hulne <serge hulne gmail com>
Cc: vala-list <vala-list gnome org>




I'm not an expert, but I'm pretty sure that with classes, assignment
means setting the variable to point to the object, and increasing the
object's reference count.






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