05-Jul-2013 13:01, TommiT пишет:
On Thursday, 4 July 2013 at 19:15:09 UTC, Dmitry Olshansky wrote:
04-Jul-2013 19:00, Regan Heath пишет:
In fact, you can generalise further.

The meaning of if(x) is "compare the value of x with 0" (in C, C++,
.. ).

The value of x for a pointer is the address to which it points.
The value of x for a class reference is the address of the class to
which it refers.

If D's arrays are reference types,

They are not. It's a half-reference no wonder it has a bit of
schizophrenia now and then.

What do you mean by D's dynamic arrays being half-reference types? And
what kind of "schizophrenia" do exhibit?

For instance passing a slice by value means passing length by value and data pointed to by pointer (hence half-ref):

void messWith(int[] slice)
{
        slice[0] = 45; //changes data pointed to, reference semantics
        slice.length = 0; //doesn't, length is not part of 'reference semantic'
}

void main(){
        auto test = [1, 2, 3];
        messWith(test);
        assert(test.length == 3);
        assert(test[0] == 45);
}

--
Dmitry Olshansky

Reply via email to