return value of functions
assume this little code
Code:
SomeObject my_func()
{
return SomeObject(...); // 1
}
void some_other_function()
{
SomeObject so = my_func();
}
what happens to the return value on return?
so where does it exist? is it appended to top of stack of the calling function?
or does it exist outside the stack frame of the caller (thus in the stack-frame of the callee which no longer exists then)?
and how long is that return value valid - so when is the destructor of it called?
immediately after the next operation (e.g. i _+_ func()) (in case there is one (e.g. func(); )?
and how is that value returned? it seems that integers and floats are returned directly through a register.
but what about objects? is the address of the returned object put into a register then?
so does anyone know where to find an explanation (or could explain) of how functions return their value - and how long it stays valid (thus when is it destroyed), and how often and when it is constructed/destroyed during that process?