|
-
July 6th, 2003, 12:14 PM
#1
Recursion vs Loop
Hi.
Recursion is slower than loops due to stacks and that stuff. However, I'm wondering if good compilers (VC++, gcc...) change some types of recursion into loops during optimization.
For example,
void demo(int i){
if (i==0) do something;
demo(i-1);
}
Since the call to the function is the last line, there's no need to save it into the stack. Ex: SML optimizes it this way. I'm wondering about C++.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|