J
jack113256
Hi everyone:
I have a question in using Callback function, there is my code:
/******* code start *********/
#include <stdio.h>
void a();
void b();
void run();
int state;
int main()
{
state = 0;
run();
}
void run()
{
if(state){
a();
}else{
b();
}
}
void a()
{
printf("a");
state = 0;
run();
}
void b()
{
printf("x");
state = 1;
run();
}
/******* code end *********/
In my opinion, the program will print "axaxaxa..." and so on, and
because the function a() and b() is called in the context of function
run(), the call trace will take more and more memory for the next
function call, which is like a recursive function call, and will
finailly stoped due to a function stack overflow.
the result is : the screen does print out "axaxaxax......" but the
function stack overflow does not happen.
Why???
I use x86-winXP machine. the windows taskmanager shows that the
process's memory does not increase. Why???
can anyone tell me the reason?
I have a question in using Callback function, there is my code:
/******* code start *********/
#include <stdio.h>
void a();
void b();
void run();
int state;
int main()
{
state = 0;
run();
}
void run()
{
if(state){
a();
}else{
b();
}
}
void a()
{
printf("a");
state = 0;
run();
}
void b()
{
printf("x");
state = 1;
run();
}
/******* code end *********/
In my opinion, the program will print "axaxaxa..." and so on, and
because the function a() and b() is called in the context of function
run(), the call trace will take more and more memory for the next
function call, which is like a recursive function call, and will
finailly stoped due to a function stack overflow.
the result is : the screen does print out "axaxaxax......" but the
function stack overflow does not happen.
Why???
I use x86-winXP machine. the windows taskmanager shows that the
process's memory does not increase. Why???
can anyone tell me the reason?