Thread overview
Passing arrays by value?
Feb 05, 2007
Lionello Lunesu
Feb 05, 2007
Lionello Lunesu
February 05, 2007
The spec doesn't specify how fixed-sized arrays are passed to functions (or, I did not find it):

void foo( in float[2] array, float x, float y )
{
    array[0] = x;
    array[1] = y;
}

It seems to me that an fixed-sized array like that could well be passed by value:

void by_ref( in float[] a, ... );
void by_value( in float[2] a, ... );
void by_ref( inout float[2] a, ... );

No?

L.
February 05, 2007
"Lionello Lunesu" <lio@lunesu.remove.com> wrote in message news:eq78nh$30b1$1@digitaldaemon.com...
> The spec doesn't specify how fixed-sized arrays are passed to functions (or, I did not find it):
>
> void foo( in float[2] array, float x, float y )
> {
>     array[0] = x;
>     array[1] = y;
> }
>
> It seems to me that an fixed-sized array like that could well be passed by value:
>
> void by_ref( in float[] a, ... );
> void by_value( in float[2] a, ... );
> void by_ref( inout float[2] a, ... );
>
> No?
>
> L.

Fixed-size arrays are passed by reference.  But I suppose passing smaller arrays by value could have its uses..


February 05, 2007
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:eq7c0j$115c$1@digitaldaemon.com...
> "Lionello Lunesu" <lio@lunesu.remove.com> wrote in message news:eq78nh$30b1$1@digitaldaemon.com...
>> The spec doesn't specify how fixed-sized arrays are passed to functions (or, I did not find it):
>>
>> void foo( in float[2] array, float x, float y )
>> {
>>     array[0] = x;
>>     array[1] = y;
>> }
>>
>> It seems to me that an fixed-sized array like that could well be passed by value:
>>
>> void by_ref( in float[] a, ... );
>> void by_value( in float[2] a, ... );
>> void by_ref( inout float[2] a, ... );
>>
> Fixed-size arrays are passed by reference.  But I suppose passing smaller arrays by value could have its uses..

Yeah. I just thought that it would be useful for that vector proposal in digitalmars.D. Walter mentioned that he'd like float[3] to behave like a 3D vector, but with vectors you'd want to have a choice to pass them either by value or by ref. Seemed logical to use in/inout for that, but at the moment, it doesn't really do anything for state/fixed-sized arrays.

L.