A simple question, but I did not find a definitive answer to Stack Overflow.
struct foo { int x; int y; int z; } foo Func() { return new foo(); } void Func2() { foo f = Func();
Is a C # structure (value type) always copied onto the stack when returning from a function, no matter how large it is? The reason I'm not sure is because for some sets of commands other than MSIL (e.g. x86), the return value should usually fit into the processor register, and the stack is not directly involved.
If so, is this a call site that preallocates space on the CLR stack for the type of expected return value?
[edit: Summary of responses:] For the purpose of the original question, the answer is no; The CLR will never (silently) block a structure just to send it as a return value.
c # struct boxing value-type return-value
Glenn slayden
source share