[:] as empty associative array literal, plus warning for null

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 5 02:17:02 PDT 2013


On Friday, July 05, 2013 11:01:17 TommiT wrote:
> 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?

Okay. Take this function.

void foo(T)(T bar)
{
    bar.mutateMe();
}

If T is a reference type, then the argument passed to foo will be mutated. If 
T is a value type, it won't be. But with arrays, it depends. If you alter 
bar's length in any way, it won't have any effect on the array that you passed 
to foo. However, if you alter any of bar's elements, then it _will_ alter the 
array that was passed in. So, arrays are sort of a half-reference type rather 
than a reference type or a value type.

- Jonathan M Davis



More information about the Digitalmars-d mailing list