Reputation: 81
I used the below two functions to test the Tail recursive optimization under MSVC08
int TailRecursively1(int i)
{
return TailRecursively1(i);
}
int TailRecursively2(std::string str)
{
return TailRecursively2(str);
}
why has TailRecursively1 been optimized, but TailRecursively2 has caused the stack overflow?
Upvotes: 5
Views: 150
Reputation: 5412
Because there are calls for std::string copy constructor and destructor when sending the str parameter by value to TailReucrsively2?
(I'm not 100% sure about this)
Upvotes: 5