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:

    “It is with deep grief that I learn of the death of your kind and brave Father; and, especially, that it is affecting your young heart beyond what is common in such cases.”
    —Abraham Lincoln (1809–1865)

    “Psychobabble is ... a set of repetitive verbal formalities that kills off the very spontaneity, candor, and understanding it pretends to promote. It’s an idiom that reduces psychological insight to a collection of standardized observations, that provides a frozen lexicon to deal with an infinite variety of problems.”
    —Richard Dean Rosen (b. 1949)