c++ how does object-value return from function in details

251 views Asked by At

Embedded types like int, char etc could be returned from function using registers, but what if function return some large object. I suggest process's stack couldn't be used for such issue, am I right? Could anyone explain how does object passed to callee?

SomeObj function() {
    SomeObj someObj;
    return someObj;
}
1

There are 1 answers

4
Wojtek Surowka On BEST ANSWER

Normally in most compilers the stack is used for this purpose. Even for large objects it is still the case. The calling function expects to find the called function value on the stack when the called function returns.

One of the solutions is to reserve the stack area before the function gets called. The called function may access this area to fill it with result (the access to the stack is not limited to the top after all).