Subj : Re: Possible FP87/EMU Problem? To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Wed Jan 14 2004 10:03 am kc wrote: >I am working in a C & assembly enviromment. In this case can you let me know how can I check the size of stack so that I would not run into stack overflow situation. You could do something like this WORD StackStart WORD StackMin int main(void) { StackStart = StackMin = _SP; do stuff print StackStart-StackMin // stack used } SubRoutine() { {local variables} if( _SP < SttackMin ) StackMin = _SP; if( _SP > StackStart ) ErrorBox(); // Wrapped! } This should let you know how much stack you are using. Adjust _stklen accordingly (add probably 4k or so for safety unless you are really tight for memory). Also, the Heap takes up some of the stack space, so don't use the heap more than you need to, or at least increase _stklen enough to accomodate it. You can also add the _heaplen=(something) to increase the heap. >>That raises a question. How can you change the stack size at run time with >>the _stklen variable, when it would seem that the compiler really needs to >>know this during the link (i.e. it reserves a certain amount of area for the >>stack). That's the job of c0x.obj. DOS, (not the linker, I don't think) gives you something like 128 bytes of stack, and the startup code in c0x sets up the stack/heap that you will really use. _stklen is defined in c0.asm as "extrn word" So, if you have a global variable _stklen, set at compile time, then c0 can read it as it is setting up for your app. The defaults are 128 bytes for NO_FLOAT, or 128 for SMALL or 256 bytes (FLOAT, not SMALL) That's really not sufficient if you are running interrupts, or are writing more than a simple program. >>the way the problem manifests itself, it’s been difficult to insert any >>helpful code, since the simple insertion of a line of code often makes the >>problem disappear. That is often the sign of an overwrite...writting past the end of your allocated data, such as int array[100]; array[100]=0; Or, before it array[-1] = 0; could reach out into the stack >>linker into moving the stack around changes the problem, but it’s not >>necessarily better when you move the stack a longer distance from our >>application. I don't think the distance has any speed issues. Once you get to another page, distance should be irrelevant. .