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

2013-04-18 Thread ixid
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. I have read a comment by Andrei that

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

2013-04-18 Thread Jacob Carlborg
On 2013-04-18 15:37, 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. I have

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

2013-04-18 Thread ixid
An array is represent using a struct with a pointer to the array data and the length, like this: struct Array { void* ptr; size_t length; } The struct is passed by value, but since it contains a pointer to the data it will be passed by reference. Note that if you do: void foo (int[]

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

2013-04-18 Thread Simen Kjaeraas
On 2013-04-18, 16:20, ixid wrote: An array is represent using a struct with a pointer to the array data and the length, like this: struct Array { void* ptr; size_t length; } The struct is passed by value, but since it contains a pointer to the data it will be passed by reference.

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

2013-04-18 Thread Maxim Fomin
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

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

2013-04-18 Thread Ali Çehreli
On 04/18/2013 07:20 AM, ixid wrote: Jacob Carlborg said: An array is represent using a struct with a pointer to the array data and the length, like this: struct Array { void* ptr; size_t length; } The terms array and slice are commonly interchanged but I think it adds to the

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

2013-04-18 Thread Steven Schveighoffer
On Thu, 18 Apr 2013 11:26:22 -0400, Maxim Fomin ma...@maxim-fomin.ru wrote: 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

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

2013-04-18 Thread ixid
I don't consider curent situation with static arrays as incosistent. When correctly understood is isn't as inconsistent, thank you for explaining, this was the knowledge I was after.