Search code examples
programming-languagesrecursionstackcompiler-errors

If an LP recursion is not allowed, then there may be cases of stack overflow?


Does the exception "Stack Overflow" is only linked to the use of recursion? In what other context we can give this exception?


Solution

    1. allocating local variables that are too large to fit on the stack, for example an array with a million elements on a 64K stack.
    2. too deep a call stack, even without recursion, if each routine has many local variables. example: a() calls b() calls c()...calls z() calls a1()... calls z99(). Each routines local variable as well as a return address for each function (and maybe a stack smashing protector) stays on the stack, until the stack unwinds as each function exits.