Tail Recursion
Page 1 of 1

Author:  Merlin [ Fri May 03, 2019 3:31 am ]
Post subject:  Tail Recursion

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.

Author:  Octocontrabass [ Fri May 03, 2019 5:01 am ]
Post subject:  Re: Tail Recursion

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group