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.
Tail Recursion
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
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.
I tried a few other compilers, but I didn't find any others that wanted to do tail call optimization on the example functions.