Dag Sverre Seljebotn skrev:
> They're syntax candy around const pointers. A reference is a) a pointer,
> b) always points to something, c) never change to point to something
> else, d) is always automatically dereferenced (so assignment etc. acts
> on the pointed-to object).
>
> int a = 4;
> int &b = a;
> b = 3; // changes a to 3. There's no way to change the pointer b itself.
>
>
A reference is not a pointer but a logical alias. So in your code above,
a and b are aliases (i.e. different names) for the same variable. That
means:
&b == &a
when b is a reference to a.
Pointers are variables. So if references were pointers, a and b would be
stored in different addresses:
&b != &a
This is the important difference between const pointers and references.
Sturla
> The current state in Cython leads to the following problem:
>
> C++:
> void f(int& x) { x = 10; }
>
> Cython:
> cdef extern from "foo.h":
> void f(int x) # int* will cause syntax errors, it must be plain int
>
> cdef int x = 3
> y = 3 # object
> f(x) # x changes to 10
> f(y) # the temporary result of conversion is changed -- y is not changed!
>
> So the current state is both inobvious and would lead to hard to find
> bugs IMO. So that's why I argue explicit support is needed in some form
> or another.
>
> Dag Sverre
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev