3 ms·
In a language with tail-call optimization, it won't.
by oldsecondhand 3y ago
In a language with tail-call optimization, it won't.
- dmurray 3y agoIt will. The negations are only being applied on the way back up the call stack. The mutual recursion version in a sibling post can be made to work though.
- ufo 3y agoSurprisingly, some compilers can automatically turn that to a loop too! Try it on clang and gcc :)
- grishka 3y agoGCC does eliminate one of the recursive calls but retains the other: https://godbolt.org/z/dof4T4vYv https://godbolt.org/z/dof4T4vYv But it also does some magic that I don't quite understand (what do the two `sub` instructions do before the `call`? Do they prepare the stack?) because x86 assembly is so confusing to me sometimes.