_stklen in Turbo C

Richard Kooijman kooijman at duteca
Thu Feb 7 22:08:38 AEST 1991


boogaard at ruunsa.fys.ruu.nl (Martin vdBoogaard) writes:

>For a variety of reasons I'd like to be able to compile (on a DOS machine
>with Turbo C) with a stack that is larger than the usual 4kB. The manual
>(yes, I *have* read the FM) says I should simply set _stklen (defined in
>dos.h) to the desired value. I just can't find out where. If I put e.g.

>  _stklen = 10000;

>at the start of main (), nothing happens, i.e. when I deliberately cause
>a stack overflow by some silly recursion, the number of times my
>stack-consuming function can call itself before triggering the `Stack
>overflow!' run-time error is always the same. (I can even make _stklen 0
>if I like.) Actually, I don't understand how a program would be able to

Turbo C doesn't do this at run-time, maybe sort of at run-time, but it
uses the value of _stklen to reserve space, which can be done at compile-time
or run-time. Maybe the start-up code reserves the space, so then it may be
called a run-time space allocation, but you cannot change _stklen anyfurther
in your program, so then it maybe called compile-time allocation.

You must declare _stklen as follows as a global (!) definition:

extern unsigned _stklen = 10000;

So this must go outside of main().



Richard.



More information about the Comp.lang.c mailing list