R
Ravindranath Gummadidala
Hi All:
I am trying to understand the C function call mechanism. Please bear with
me as I state what I know:
"every invocation of a function causes a frame for that function to be
pushed on stack. this contains the arguments this function was called
with, address to return to after return from this function (the location
in the previous stack frame), location of previous frame on stack (base or
start of this frame) and local variables of this function"
my question is how is a value returned from this function. say the value
is stored in some local variable, is the address of this local variable
passed to the caller (this does not seem right because the current frame
gets popped before caller tries to access the location but then again the
value should still be there intact as no changes have been made yet i.e.
another function's frame has not overwritten values there). or is this
return value stored temporarily on the heap and the caller gets it from
there somehow or is the value stored in some register and obtained from
there. in such a case how would a structure be returned? we could store
the struct on heap but say the function does not do that, just creates a
struct object and returns that. how then are values (i
deliberately use values meaning the possible use of a struct to
return multiple values) returned from functions?
Any pointers will be appreciated.
Thanks,
Ravi.
I am trying to understand the C function call mechanism. Please bear with
me as I state what I know:
"every invocation of a function causes a frame for that function to be
pushed on stack. this contains the arguments this function was called
with, address to return to after return from this function (the location
in the previous stack frame), location of previous frame on stack (base or
start of this frame) and local variables of this function"
my question is how is a value returned from this function. say the value
is stored in some local variable, is the address of this local variable
passed to the caller (this does not seem right because the current frame
gets popped before caller tries to access the location but then again the
value should still be there intact as no changes have been made yet i.e.
another function's frame has not overwritten values there). or is this
return value stored temporarily on the heap and the caller gets it from
there somehow or is the value stored in some register and obtained from
there. in such a case how would a structure be returned? we could store
the struct on heap but say the function does not do that, just creates a
struct object and returns that. how then are values (i
deliberately use values meaning the possible use of a struct to
return multiple values) returned from functions?
Any pointers will be appreciated.
Thanks,
Ravi.