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:

    “In deep sadness there is no place for sentimentality.”
    —William Burroughs (b. 1914)

    “Henry B. Adams was the first in an infinite series to discover and admit to himself that he really did not care whether truth was, or was not, true. He did not even care that it should be proved true, unless the process were new and amusing. He was a Darwinian for fun.”
    —Henry Brooks Adams (1838–1918)