Call Stack

V

Victor Bazarov

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
 
R

Richard Herring

Vinodh Kumar P said:
What is call stack?

It's the record of which functions were called and have not yet
returned, on the way to the current point of execution. Debuggers
usually provide some way of viewing it.
I am sorry if its perceived as an off topic.

As a generic concept it's almost on-topic, though there's nothing
C++-specific about it. How it's implemented on any particular platform
would definitely be off-topic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,516
Latest member
ChrisHibbs

Latest Threads

Top