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:

    There was a sound of revelry by night,
    And Belgium’s capital had gathered then
    Her beauty and her chivalry, and bright
    The lamps shone o’er fair women and brave men;
    A thousand hearts beat happily; and when
    Music arose with its voluptuous swell,
    Soft eyes looked love to eyes which spake again,
    And all went merry as a marriage-bell;
    But hush! hark! a deep sound strikes like a rising knell!
    George Gordon Noel Byron (1788–1824)

    You need an infinite stretch of time ahead of you to start to think, infinite energy to make the smallest decision. The world is getting denser. The immense number of useless projects is bewildering. Too many things have to be put in to balance up an uncertain scale. You can’t disappear anymore. You die in a state of total indecision.
    Jean Baudrillard (b. 1929)