This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: allocation on the stack
- To: gcc at gcc dot gnu dot org
- Subject: Re: allocation on the stack
- From: Bruno Haible <haible at ilog dot fr>
- Date: Wed, 29 Sep 1999 18:17:52 +0200 (MET DST)
- Cc: list at Cal040031 dot student dot utwente dot nl
Thomas van Gulick asks how to catch stack overflow and continue running.
On those OSes which support it (Linux-2.2 with glibc-2.1, Solaris, OSF/1,
Win32, maybe Irix), you can catch stack overflow using the sigsegv library
[1]. But be warned that it's really hairy stuff, and is not reliable because
it needs heuristics to distinguish a stack overflow from a regular SIGSEGV.
If your problem is not infinite recursion but huge arrays, it's a good idea
to allocate temporary memory with alloca when it's small (say, < 64 KB),
and with malloc when it's large.
Bruno
[1] ftp://ftp.santafe.edu/pub/gnu/sigsegv-1.1.tar.gz