Passing dynamic arrays

Jesse Phillips jessekphillips+D at gmail.com
Tue Nov 9 07:31:34 PST 2010


Steven Schveighoffer Wrote:

> It depends on your definition of reference type.  I agree with Daniel.  If  
> you want to get into academic definitions, yes, 'technically' an array is  
> a reference, but it's confusing to someone who's not interested in  
> exploring the theoretical parts of computer science.

I think viewing a reference as a pointer is wrong. But I did already agree that since it is claimed to be passed by reference it is odd that the length is not part of it.

> I think of an array as a hybrid between a reference and a value type.  The  
> data is passed by reference, the length is passed by value.  This mean  
> changing the length only affects the local copy, but changing the data  
> affects all arrays that point to that data.

Yet this still isn't complete because if you resize the array the data may not point to that same data anymore. I do not see this as an issue, but if you understand this, the fact that the length is passed by value isn't important, because you won't be relying on whether it points to the same data or not.

D arrays are done differently then other types/languages. I don't have an issue with changing the wording to clarify, but if we are going to do that suggestions should be made. But saying it isn't a reference does nothing.

> There is no more distinction between slices or arrays, they are  
> one and the same. 

Yeah, I'm glad about this. Arrays are much nice for this.


More information about the Digitalmars-d mailing list