Answer the question
In order to leave comments, you need to log in
What is a call stack?
When debugging a program in Microsoft Visual Studio, I came across such a field as Call Stack. Can someone explain in a little more detail what it is, why it is and how to use it. I don't know English very well, so I didn't search on English-language sites. Maybe someone with experience will explain or give a link to read about it (only in Russian), I will be grateful.
Answer the question
In order to leave comments, you need to log in
Part of the computer's memory is dedicated to the stack.
When you call a function in your code, the function's parameters are pushed onto the stack (often, but there are other ways). It is also necessary to know where to return from the function - the return address is put on the stack.
Call Stack - a window that displays all nesting levels of function calls.
Там вы можете узнать, в какой функции вы сейчас находитесь, из какой функции она была вызвана и так далее рекурсивно наверх вплоть до точки входа в программу.
Собственно call stack вычисляется на основе информации из стека.
Once upon a time there was a goto statement and programs looked like this
10 let a = 5
20 if a =5 then goto 100
30 print "Вот и все, ребята"
40 exit
100 print "Да, наше a = 5"
110 goto 30
main () {
call program1;
call program2;
}
program1 () {
call program 3;
return;
}
program2 () {
call program3;
return;
}
program3 () {
return;
}
So that when execution stops (at a breakpoint or when an exception is thrown), find out in which function (and possibly with the number of the line of code) the stop occurred, with nesting.
Example:
void foo2() {
foo3(5 / 0);
}
void foo1() {
foo2();
}
void main() {
foo1();
}
foo2
foo1
main
Call stack is a call stack, a hardware feature of all large processors.
int foo()
{
int y = ...;
if (y < 0)
y = -y;
return y;
}
void bar()
{
int x = foo();
if (x != 0)
bar();
foo();
}
void main()
{
int z = foo();
bar();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question