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:

    Yet here at least an earnest sense
    Of human right and weal is shown;
    A hate of tyranny intense,
    And hearty in its vehemence,
    As if my brother’s pain and sorrow were my own.

    O Freedom! if to me belong
    Nor mighty Milton’s gift divine,
    Nor Marvell’s wit and graceful song.
    Still with a love as deep and strong
    As theirs, I lay, like them, my best gifts on thy shrine!
    John Greenleaf Whittier (1807–1892)

    Whatever we have got has been by infinite labour, and search, and ranging through every corner of nature; the difference is that instead of dirt and poison, we have rather chosen to fill our hives with honey and wax, thus furnishing mankind with the two noblest of things, which are sweetness and light.
    Jonathan Swift (1667–1745)