Hello ๐ I have a general question about the following piece of code:
// Version 1: returns a structure
struct Foo get_foo(T *t) {
return (Foo) {
.t=t
};
}
// Version 2: pass a pointer
void get_foo(T *t, struct Foo *result) {
*result = (Foo) {
.t=t
};
}
in my understanding, the first version will require to copy the structure on the stack when returning the function, while the second actually makes the copy inside the function itself. However, both will use the stack.
Not talking about which one is more flexible in front of the question "what if the memory should be dynamically allocated" or alike, is there a clear downside of using V1 over V2, in terms of stack-management ?