public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to get current stack size ?
@ 2003-02-20  2:05 Igor Bukanov
  2003-02-20  8:59 ` Fergus Henderson
  0 siblings, 1 reply; 2+ messages in thread
From: Igor Bukanov @ 2003-02-20  2:05 UTC (permalink / raw)
  To: gcc

Hi!

Is there any internal function in GCC that I can use to determine 
currently consumed stack space? Or I should better ask glibc guys about it?

I would like to prevent too deep recursion in a recursive descent parser 
which parse external data and limiting amount of stack space that can be 
consumed during recursion seems to be a simple solution. Initially I 
thought to use something like the following scheme which calculates 
address differences:

char* stack_mark;

void parse() {
	char dummy;
	stack_mark = &dummy;
	...
	recursively_called_function();
	
	....

}

void recursively_called_function() {
	char dummy;
	ptrdiff_t consumed_stack_size = &dummy - stack_mark;
	if (consumed_stack_size > STACK_LIMIT
	    || -consumed_stack_size > STACK_LIMIT)
	{
		report_error();
	}
	...
}

The trouble is that parse() can be called from some other libraries that 
may also be under deep recursion and checking against stack size 
consumed during parse may miss stack overflow. So I need absolute value 
for the stack size.

Thanks in advance, Igor Bukanov


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-02-20  7:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20  2:05 How to get current stack size ? Igor Bukanov
2003-02-20  8:59 ` Fergus Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).