2. Introduction
Data can be organized in many different ways. For
example if we want to store 5 numbers we can store them
in five different variables ,an array , a linked list ,etc.
All these different ways of organizing data are known as
data structures.
The compiler uses one such data structure called “stack”
for implementing functions call.
3. Stack
Stack is a LIFO (Last In First Out) data structure.
This means that the last item to get stored on the stack
(often called Push operation) is the first one to get out of
it (often called Pop operation)
For each function call, there's a section of the stack
reserved for the function. This is usually called a stack
frame.
4. …
Stack frame of main() looks something like this :
It is also called activation
record.
A stack frame exists
whenever a function has
started, but yet to complete.
5. Suppose, inside of body of main() there's a call to foo().
Suppose foo() takes two arguments. One way to pass the
arguments to foo() is through the stack. Thus, there needs
to be assembly language code in main() to "push"
arguments for foo() onto the stack. The result looks like:
10. Calling convention
Calling convention decides whether the parameters being
passed to the function are pushed on the stack from left-
to-right or from right-to-left.
Calling convention also decides that the popping of data
from stack is done by which function.
Above example used CDecl calling convention.