Hard
The same recursive sum without the accumulator
The recursive call here is not in tail position: the addition of n happens after it returns. Built at -O0, calling sumTo(1000000) segfaults. Built at -O2 with GCC or Clang, it returns 500000500000 promptly. What accounts for the difference?
main.cpp
long sumTo(long n) {
if (n == 0) return 0;
return n + sumTo(n - 1); // addition happens AFTER the recursive call returns
}16 of 44 in Compilers