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:

    There is something wrong about the man who wants help. There is somewhere a deep defect, a want, in brief, a need, a crying need, somewhere about that man.
    Herman Melville (1819–1891)

    The unique eludes us; yet we remain faithful to the ideal of it; and in spite of sense and of our merely abstract thinking, it becomes for us the most real thing in the actual world, although for us it is the elusive goal of an infinite quest.
    Josiah Royce (1855–1916)