Vinodh said:
What is call stack?
I am sorry if its perceived as an off topic.
A common understanding of what a call stack is can be illustrated
easily here:
void foo();
void bar();
int main() {
// here the call stack is
// int main(void)
// __some_internal_c++_startup_code
foo();
}
void foo() {
// here the call stack is
// void foo(void)
// int main(void)
// __some_internal_c++_startup_code
// as you can see the current function (foo) is at the top
// of the call stack
bar();
}
void bar () {
// here the call stack is
// void bar(void)
// void foo(void)
// int main(void)
// __some_internal_c++_startup_code
// as you can see the current function (bar) is now at the top
// of the call stack
}
As to the definition, it's probably "a structure that reflects the path
to a particular place in the program's execution from the beginning via
all function calls".
A call stack does not reflect how the program got to that point except
by tracking the function calls.
<offtopic>
The usefulness of the call stack is in the fact that often you can infer
the execution steps from it by looking what functions are in the middle.
It also often contains the information _from_where_ each function call
was made (file name and line number), especially if the code is compiled
with debugging information. Also, many debuggers are capable of showing
the values of the arguments passed into the function. [My example doesn't
have any arguments]
</offtopic>
Victor