[comp.sys.amiga.tech] Aztec-C and Stack size

zupke@jato.Jpl.Nasa.Gov (Brian Zupke ) (04/17/89)

Howdy!

Does anyone know if programs written with Manx Aztec-C require a minimum 
stack size of 8000 bytes?  Well, it seems to be the case with a program
that I'm working on.  It works fine when the stack is set to at least 8000,
but will crash when it's set to 4000.  Any ideas?

Thanks!

--Brian

lindwall@sdsu.UUCP (John Lindwall) (04/18/89)

In article <1119@jato.Jpl.Nasa.Gov>, zupke@jato.Jpl.Nasa.Gov (Brian Zupke ) writes:
> 
> Howdy!
> 
> Does anyone know if programs written with Manx Aztec-C require a minimum 
> stack size of 8000 bytes?  Well, it seems to be the case with a program
> that I'm working on.  It works fine when the stack is set to at least 8000,
> but will crash when it's set to 4000.  Any ideas?
> 
> Thanks!
> 
> --Brian

	I'll probably not be the only offering this suggestion but just in
case --

	Take a look at the number and/or size of any automatic (local)
variables you are declaring in your various functions.  Automatic variables
are allocated on the stack, so if you claim too much stack space for them
you may cause overflow.  As a test of this problem you can compile with the
+m switch which enables stack-checking code to be performed  as part of the
function startup sequence.  The default action on stack-overflow is to print
a message and exit, but by defining a function __stkover() to overide the
library version you can do your own graceful exit.

	An example of a 'bad' function might be

int
foo ()
{
	int ImRealBig[10000];		/* Bye-Bye Stack! */
...
}

	The description of the +m option is from the manual, but I have not 
tested it personally.  Let us know if this is the problem and if the +m
option performs as advertised!


-------------------------------------------------------------------------------
	The above opinions are mine, not my employer's nor my school's

John Lindwall					johnl@tw-rnd.SanDiego.NCR.COM

zupke@jato.Jpl.Nasa.Gov (Brian Zupke ) (04/19/89)

>  [suggest problem is local variables] 
>As a test of this problem you can compile with the 
>+m switch which enables stack-checking code to be performed  as part of the 
>function startup sequence.  
>   The description of the +m option is from the manual, but I have not  
>tested it personally.  Let us know if this is the problem and if the +m 
>option performs as advertised! 

    Well, local variables definately caused the crash (I have several large
arrays).  To verify that my local variables were the problem, I made them
much smaller and the program ran fine with a stack size of 4000.  I used 
the +m (interesting that my Aztec-C manual doesn't mention this option!)
option when I compiled  my program but when I ran it, it crashed like it
normally did, so apparently the option doesn't work.    

--Brian