_stklen in Turbo C

Martin vdBoogaard boogaard at ruunsa.fys.ruu.nl
Fri Feb 8 22:15:00 AEST 1991


Thanks to all the people who responded to my question about the use of
_stklen in Turbo C. As was pointed out, statements like

  extern unsigned _stklen = 10000;

have to be made outside any function. And indeed, all this could have
been found in the HELPME!.DOC file. Having been told how to do the
trick, I have tried to detect the influence of assignements like this.
However, nothing happened, because I was using the medium memory model.
This brings up a second question, i.e. when does Turbo C (with the -N
compiler option) signal a stack overflow?

Let's call the current size of the heap H and the size of the static
data D. Stack overflow is signaled by your program when the current stack
size exceeds S_max. It seems to me that in Turbo C's small-data memory
models (tiny, small, medium) at any time we simply have S_max = 64kB - H
- D, in other words: the value of _stklen is in this case completely
irrelevant. In the large-data memory models (compact, large, huge) the
role of _stklen is what you expect it to be: S_max = _stklen.

All this is, as far as I know, not in Borland's manuals. The section on
the -N compiler option hails the stack overflow detection as `a real
lifesaver', but there is no adequate info on what to do about stack
overflow (except simplifying your code and minimizing the use of local
variables) and what the choice of the memory model has got to do with
this. Is there any reason why we're not able to simply tell TLINK how
large we want the stack to be?


Martin J. van den Boogaard         | Dept. of Atomic & Interface Physics
                                   | Debye Institute--Utrecht University
boogaard at fys.ruu.nl                | P.O. Box 80.000, NL-3508 TA Utrecht
boogaard at hutruu51.bitnet           | the Netherlands, +31 30 532904
------------------------------------------------------------------------



More information about the Comp.lang.c mailing list