Databases Reference
In-Depth Information
Figure 1.2
Stack grows down
(from high memory
to low memory).
The stack is used to manage the entire function calling process, including
parameter passing and return values. When a function is called, the func-
tion's parameters are pushed onto the stack. Then an area is allocated for the
return address. Then the frame pointer is pushed onto the stack (the frame
pointer is used to reference the local variables and the function parameters
that are always at fixed offsets from the frame pointer). Then the function's
local automatic variables are allocated. At this point the program can run the
function's code and has all of the required variables available. As an example,
if you call a function foo(“ab”, “cd”) that is defined as shown, the stack struc-
ture will include allocations, as shown in Figure 1.3.
int foo(char* a, char* b) {
char buf[10];
// now comes the code
...
}
Suppose that the first thing that the developer of foo does is copy the
first parameter into the local variable so that he or she can manipulate the
 
Search WWH ::




Custom Search