Path: utzoo!attcan!uunet!samsung!sdd.hp.com!caen!uflorida!palmetto.cis.ufl.edu!jdb From: jdb@palmetto.cis.ufl.edu (Brian K. W. Hook) Newsgroups: comp.lang.c Subject: Re: _stklen in Turbo C Keywords: stack, DOS, Turbo, Borland Message-ID: <26724@uflorida.cis.ufl.EDU> Date: 6 Feb 91 13:35:33 GMT References: <1921@ruunsa.fys.ruu.nl> Sender: news@uflorida.cis.ufl.EDU Organization: UF CIS Dept. Lines: 46 In article <1921@ruunsa.fys.ruu.nl> boogaard@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 >change its own stack size at run time. Is this really what happens (or, >in my case, doesn't happen)? Who has a working example of how to do this? Well, if you look at the code in the Turbo C++ Docs (which is all I have) then you will notice that it states that you should define _stklen as an extern. _stklen is an internal variable that I BELIEVE is used as part of the start-up C module....? Anyway, here is how I do it (and it does work!) #include /* Whatever needs to be include */ extern unsigned _stklen=8192; /* This is off the top of my head, but I */ /* believe _stklen is an unsigned int, but */ /* it could be signed... */ void main ( void ) /* Of course you could change the args and returns */ { /* ** Put your code here */ } The key here is the extern declaration, that lets the compiler know that you are referring to a variable that is in another module (the startup module I believe)....If you put the declaration inside main() it wouldn't work, especially if you didn't declare it an extern (if you didn't, TC would just believe that you are declaring a new local variable). Hope this helps, Brian