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:

    Come now, let us go and be dumb. Let us sit with our hands on our mouths, a long, austere, Pythagorean lustrum. Let us live in corners, and do chores, and suffer, and weep, and drudge, with eyes and hearts that love the Lord. Silence, seclusion, austerity, may pierce deep into the grandeur and secret of our being, and so diving, bring up out of secular darkness, the sublimities of the moral constitution.
    Ralph Waldo Emerson (1803–1882)

    Vanity is as advantageous to a government as pride is dangerous. To be convinced of this we need only represent, on the one hand, the numberless benefits which result from vanity, as industry, the arts, fashions, politeness, and taste; and on the other, the infinite evils which spring from the pride of certain nations, a laziness, poverty, a total neglect of everything.
    —Charles Louis de Secondat Montesquieu (1689–1755)