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:

    from deep in the dark head
    his smile glowing
    outward into the
    room’s severe twilight,
    he lies....
    Denise Levertov (b. 1923)

    We know that every person who is loved feels transformed, unfolded, and he unfolds everything, the most intimate as well as the most familiar, to the one who loves him as well as to himself.... The person one loves is as ungraspable as the universe, as God’s infinite space, he is boundless, full of possibilities, full of secrets.
    Max Frisch (1911–1991)