Reputation: 1726
Environment: CodeBlocks on Windows 7 64 bit
void recurse(int i)
{
int a = 9;
cout<<i<<endl;
recurse(++i);
}
int main()
{
recurse(1);
return 0;
}
When I run the above code in release mode, it easily exceeds 600k recursion calls, when in Debug mode it fails after 43385 calls.
Any idea why that is happening?
It is not because of the compiler optimizing away the a=9
, without that statement I get 65078 calls in debug mode
Upvotes: 0
Views: 178
Reputation: 8661
A debug build will perform stack overflow checks. To do that, it needs to alocate a bit of stack memory for each function call.
Besides, parameters will also be passed on the stack while a release build will probably use registers.
Upvotes: 1