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:

    Judicial judgment must take deep account ... of the day before yesterday in order that yesterday may not paralyze today.
    Felix Frankfurter (1882–1965)

    Let us then examine this point, and say, “God is, or he is not.” But to which side shall we incline? Reason can decide nothing here. There is an infinite chaos which separates us. A game is being played at the extremity of this infinite distance where heads or tails will turn up. What will you wager?
    Blaise Pascal (1623–1662)