A simple question, but I haven't found a definitive answer on Stack Overflow.
struct foo { int x; int y; int z; }
foo Func()
{
return new foo();
}
void Func2()
{
foo f = Func(); // did boxing and unboxing occur?
}
Is a C# struct (value type) always copied to the stack when returned from a function, no matter how large it might be? The reason I'm unsure is that for some instruction sets other than MSIL (such as x86), a return value usually needs to fit into a processor register, and the stack is not directly involved.
If so, is it the call site that pre-allocates space on the CLR stack for the (expected) value return type?