Tail Recursion

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Tail Recursion

Post by AndrewBuckley »

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_a ... timization correct?
It seems to think the order the lines occur is more important than the recusion being equivalent to the caller.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Tail Recursion

Post by Octocontrabass »

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.
Post Reply