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:

    Roll on, thou deep and dark blue Ocean,—roll!
    Ten thousand fleets sweep over thee in vain;
    Man marks the earth with ruin,—his control
    Stops with the shore;
    George Gordon Noel Byron (1788–1824)

    What means the fact—which is so common, so universal—that some soul that has lost all hope for itself can inspire in another listening soul an infinite confidence in it, even while it is expressing its despair?
    Henry David Thoreau (1817–1862)