Re: Testing Program Question
* Alf P. Steinbach:
* James Kanze:
In fact, the fact that running out of stack cannot be gracefully
caught means that we do have to do something. But don't confuse
the cause and the effect.
Another angle is to focus on prevention rather than detection.
A semi-portable way to check for available stack space is to use the de
facto standard 'alloca', which it seems has the same behavior on a wide
range of platforms, returning NULL if there isn't enough space.
Curiously, I've never used that solution; what it solves seems to not be
that big a problem in practice, i.e. it's probably a solution looking
for a problem?
And I can imagine that on some systems the alloca that I mentioned here
might cause virtual allocated address space to be mapped to actual memory.
Which might slow down things.
Oh, discovery:
the reason that I've never used the alloca technique that I mention above seems
to be that alloca *is not* consistently defined on different platforms.
<url: http://www.mkssoftware.com/docs/man3/alloca.3.asp>
guarantees 0 on error,
<url: http://msdn.microsoft.com/en-us/library/wb1s57t5%28VS.71%29.aspx>
guarantees a "stack overflow exception" on error, and
<url: http://www.kernel.org/doc/man-pages/online/pages/man3/alloca.3.html>
says the error behavior is undefined.
Perhaps the group can benefit from this info.
Cheers,
- Alf