[comp.sys.ibm.pc.programmer] Turbo-C stack problem

sun@me.utoronto.ca (Andy Sun Anu-guest) (07/20/90)

Hi,

Does anybody out there know if I can alter the stack size (increase it to be
specific) in Turbo C? And if yes, how can it be done? I got a stack overflow
error in my program (compiled using small model) and after I flipped through
all the manuals, I still cannot find anything that allow me to change the
stack size (there is a global variable called _stklen, but it doesn't mention
exactly how it is used). I CANNOT use anything higher than small model since
I will have a memory allocation error (insufficient memory). BTW, I am using
Turbo C version 1.5. Any suggestion and advises are welcome.

Andy

_______________________________________________________________________________
Andy Sun                            | Internet: sun@me.utoronto.ca
University of Toronto, Canada       | UUCP    : ...!utai!me!sun
Dept. of Mechanical Engineering     | BITNET  : sun@me.utoronto.BITNET

gordon@osiris.cso.uiuc.edu (John Gordon) (07/20/90)

	To change the stacklength, it is very easy:  just say

		_stklen = (num of bytes desired) in your program.

		example:  _stklen = 48000;

	NOTE: I think it is required to set it globally, not locally.
		Also, I did it in 2.0, not 1.5.


---
John Gordon
Internet: gordon@osiris.cso.uiuc.edu        #include <disclaimer.h>
          gordon@cerl.cecer.army.mil       #include <clever_saying.h>
GEnie:    j.gordon14                  

brucee@runxtsa.runx.oz.au (Bruce Evans) (07/23/90)

In article <1990Jul20.165800.23672@ux1.cso.uiuc.edu> gordon@osiris.cso.uiuc.edu (John Gordon) writes:
>
>	To change the stacklength, it is very easy:  just say
>
>		_stklen = (num of bytes desired) in your program.

This must be done with a global initializer (i.e. at compile time) since it
is used by the startup code (before main() ).

I used this to force a very small stack in a program that did little more
than shell out to another program, to stop it wasting 64K. It was necessary
to set _heaplen to something small too. I think the heap length is set to
64K - data length - _stklen otherwise (for small model TC 2.0). For details,
see the source file C0.ASM.