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

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Feb 21 15:24:15 PST 2008


"Jason House" <jason.james.house at gmail.com> wrote in message 
news:fpl0tk$hco$1 at digitalmars.com...
>
> This looks like doing the following in C++:
> C toC(){
>  C c;
>  return c;
> }
>
> Which is an error (regardless of what the compiler says).  c is allocated 
> on
> the heap and is deallocated when the function exits.  It may be that the
> same effect is happening here.  I'm sure this kind of thing could get 
> fixed
> in a similar way to how full closures were fixed...

Not at all.. that declaration of 'c' has nothing to do with the heap, it's 
allocated on the stack, and when you return it, you're returning it by 
value.  This is valid C++ code AFAIK.

I think you're thinking of _this_:

char* something()
{
    char foo[10];
    return foo;
}

Which _is_ illegal, because foo is allocated on the stack and you can't 
return arrays by value in C/C++.

Which, coincidentally, is why you can't return statically-sized arrays in D, 
since they're supposed to be "C-like" in many ways. 




More information about the Digitalmars-d-learn mailing list