There is nothing special about struct ; this is something special about array types that don't allow them to return from a function directly.
A struct expression is treated as an expression of any other type without an array; it evaluates the value of struct . This way you can do things like
struct foo { ... }; struct foo func( void ) { struct foo someFoo; ... return someFoo; }
The expression someFoo is evaluated by the value of the struct foo object; the contents of the object are returned from the function (even if the contents contain arrays).
An array expression is handled differently; if it is not an operand of the sizeof or unary & operators, or if it is not a string literal used to initialize another array in the declaration, the expression is converted ("decays") from an array of type " T " to "pointer to T ", and the value of the expression is the address of the first element.
Thus, you cannot return an array by value from a function, because any reference to an array expression is automatically converted to a pointer value.
John Bode Apr 26 '16 at 18:00 2016-04-26 18:00
source share