Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: Torio on August 24, 2012, 09:05:42 am

Title: [68k] - Stack limit ?
Post by: Torio on August 24, 2012, 09:05:42 am
Hello,
I'm writing a C program (with GCC4TI) in which many functions are called inside an other, etc...
It seems I've reached a point where too many functions are stacked and the program crashes, throwing sometimes (but not always) a memory error.

Is it possible to increase the size of the stack in C ?
Thank you in advance,
Torio.
Title: Re: [68k] - Stack limit ?
Post by: Lionel Debroux on August 24, 2012, 09:20:04 am
Quote
Is it possible to increase the size of the stack in C ?
Basically, no.
The user portion of the stack goes from 0x4200 to 0x400 downwards, and the OS uses some of that itself.

What you need to do is reduce stack usage by eliminating SAVE_STACK (saving/restoring the screen yourself, in an allocated memory block or through the method used by the Home Screen Restore program), reducing call nesting, and potentially by using the registers to pass parameters (__attribute__((__regparm__)) on single functions, -mregparm=5 compiler switch).
Title: Re: [68k] - Stack limit ?
Post by: Torio on August 24, 2012, 09:40:38 am
I de-checked the Save/Restore LCD Contents box in Program Options and saved the home screen in an allocated memory block, and the problem dissapeared.
I hope that I won't have to reduce stack usage again, because that :

Quote
potentially by using the registers to pass parameters (__attribute__((__regparm__)) on single functions, -mregparm=5 compiler switch).

I didn't understand it at all.  :banghead:

Thank you again, Lionel, for your always-useful answers.
Torio