OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:27 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Tail Recursion
PostPosted: Fri May 03, 2019 3:31 am 
Offline
Member
Member

Joined: Thu Jan 29, 2009 9:13 am
Posts: 95
My understanding of C is fairly basic, so I don't want to change the wiki if I am incorrect, but is the tail recursive example on https://wiki.osdev.org/Tail_Recursion_and_Tail_Call_Optimization correct?
It seems to think the order the lines occur is more important than the recusion being equivalent to the caller.


Top
 Profile  
 
 Post subject: Re: Tail Recursion
PostPosted: Fri May 03, 2019 5:01 am 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
The order of the lines makes no difference to any modern optimizing compiler. With sufficient optimizations enabled, GCC produces identical tail-call-optimized code for both example functions. Clang does the same thing (though its results are not the same as GCC's).

I tried a few other compilers, but I didn't find any others that wanted to do tail call optimization on the example functions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group