Stack Overflow - Very Deep or Infinite Recursion

Very Deep or Infinite Recursion

The most common cause of stack overflow is excessively deep or infinite recursion. Languages like Scheme, which implement tail-call optimization, allow infinite recursion of a specific sort—tail recursion—to occur without stack overflow. This works because tail-recursion calls do not take up additional stack space.

An example of infinite recursion in C.

int foo { return foo; }

The function foo, when it is invoked, continues to invoke itself, using additional space on the stack each time, until the stack overflows resulting in a segmentation fault.

Read more about this topic:  Stack Overflow

Famous quotes containing the words deep and/or infinite:

    “Penny: Grandpa found the cutest place near where Alice is, right on the ocean.
    Paul: Lake, Penny. Lake.
    Penny: That’s what I said. Lake. We’re gonna invite you all up to go deep sea fishing.”
    —Robert Riskin (1897–1955)

    “My belief is that science is to wreck us, and that we are like monkeys monkeying with a loaded shell; we don’t in the least know or care where our practically infinite energies come from or will bring us to.”
    —Henry Brooks Adams (1838–1918)