Error: functions cannot return static array float[4u][4u]

Derek Parnell derek at nomail.afraid.org
Thu Feb 21 18:08:26 PST 2008


On Fri, 22 Feb 2008 00:25:44 +0000, Spacen Jasset wrote:

> Derek Parnell wrote:
>> why can't D handle 'ref' and 'out' static arrays either?
>> In other words, this below won't compile...
>> 
>>   void toFloatArray4x4(ref float[4][4] p) ...
>> 
>> So what is the rationale for that?
>> 
> ... arrays have pass by reference semantics unlike 
> stucts, ints and other basic types.

Agreed, but why is that a problem? 

The way I see it, the called function gets the address of the first element
in the static array and the compiler knows the layout of the array "[4][4]'
so why can't the called function use it like that? Currently, it seems like
an artificial restraint.

I can't see why this below should be hard to implement...

// -------------
void toFloatArray4x4(ref float[4][4] p)
{
    int n;
    n = 1;
    for (int i = 0; i < 4; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            p[i][j] = n;
            n++;
        }
    }
}

void main()
{
    float[4][4] r;
    
    toFloatArray4x4( r );
}

// ---------

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
22/02/2008 1:03:40 PM


More information about the Digitalmars-d-learn mailing list