In considering a scenario where we may not wish to always store the return value of a function in multiple calls, take this code:
int foo()
{
return 1;
}
which is called from the following procedure.
void main()
{
foo();
}
What happens to the return value of foo? In not finding a variable address does the compiler put it on a spare register- or does it get wiped when the next statement is executed? If now instead the return value is stored somewhere:
void main()
{
int retval;
retval = foo();
}
What's the performance difference between the two scenarios? Is not storing retval somewhere going to cause any issues with the stack management somewhere down the track?
Edit: Own config: Toolset: V100, __cdecl (/Gd): Running Win32 in VS10 compiling as C++ - would inlining come into play?
Can we but guess as to how many many specific configurations apply to a given set of answers. Might be enough for a small book!
As to performance, int was a poor choice, perhaps float or double makes for more impact?
This question differs from the proposed duplicate like this:
Given the return address of foo is added to a call frame, one scenario is that the address of retval is placed below it, but if retval is NULL there is an extra overhead?