Why are fixed length arrays passed by value while variable are passed by reference?

Maxim Fomin maxim at maxim-fomin.ru
Thu Apr 18 08:26:22 PDT 2013


On Thursday, 18 April 2013 at 13:37:45 UTC, ixid wrote:
> I know this will not be changed, I just want to understand why 
> it is as it is.
>
> My naive thought is that consistency is the best scheme and 
> that everything should have been passed by value or everything 
> by reference unless the user specifies otherwise.

Classifying types as passed by value and passed by reference
types is a little bit confusing sometimes)

In D, like in C, everything is passed by value (unless parameter
is specified as ref, also note that in C passing by reference is
a simulation done by pointers). Confusion comes when there is
data which points to another data. Learning how data types are
constructed is better approach than classifying their categories.
The former sometimes can explain what the latter cannot:

http://dpaste.dzfl.pl/7744d11e

AA array behaves like a reference type, but when it is reset to
null, it acts like a value type. Contradiction is caused by
complex data structes with mixed structs and pointers in AA
implementation.

> I have read a comment by Andrei that they tried making fixed 
> length arrays into reference types but it did not work well. 
> Did the current situation arise through the reality of language 
> development or is there a reason for the inconsistency?

I don't consider curent situation with static arrays as
incosistent.


More information about the Digitalmars-d-learn mailing list