Re: Stack Overflow Detection



On May 30, 4:37 pm, Vladimir Vassilevsky <antispam_bo...@xxxxxxxxxxx>
wrote:

The main problem with it is that you
never know for sure what is the maximum stack usage.


Are you sure about that? Would it not just be a case of determining
how much stack space each of the function's use, and then looking at
the logic of the program to see what could possibly be the deepest
level?

Even if there were recursive functions involved, they could still be
given a finite limit:

double RaiseToIntPower(double val,unsigned exp)
{
if (0 == exp) return 1;

if (1 == exp) return val;

return val * RaiseToIntPower(val,--exp);
}

For example the logic of the program my prevent "exp" from being more
than 7, or then again you could hardcode your own "if (exp > 7)"
within the function.

(Obviously it's a stupid idea to implement this function as a
recursive funciton, but it was an easy example to throw together for
the purposes of explanation.)
.