Recursive call and Stack 
Author Message
 Recursive call and Stack

Question  2 : Recursive Call & Stack
=========================

I'm learing some simple Interpreter technique, using expression-parsing,
currenlty on
win9x, and will port to Linux as well.

Since expression parsing is using recursive call, and each call will use the
stack space,
So I wondering If the program space have limited stack size , this will
cause trouble if the stack
space is not enough.

On MS-DOS
   System stack space is fixed on config.sys , Program stack size ? depend
on system stack ?

On Win3.x
  The window program need to declare the stack space used by the program.
(myprog.def),
  Still depend on Config.sys stack space allocation ?

On Win32 (win95 and above)
   However, the stack space (size) no need to be declared, so
   I assume it is either dynamic allocated or somehow using other method for
function call.

On Unix
   How is the stack allocated ? static or dynamic allocated by the system ?
   How differ is it on different Unix (HP, Sun, System 5, Linux etc) ?

Any Comment ?

TQ,

    Ng

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>
#inlcude <nospam>
int main()
{
    printf("remove nospam from my email to reply to me\n");
    return 0;

Quote:
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Wed, 29 Jan 2003 03:00:00 GMT  
 Recursive call and Stack
On Sat, 12 Aug 2000 12:00:46 +0800, "anonymous"

Please learn how to post properly.  Do not start your subject lines
with "Re:".  News software adds this automatically when you reply to a
message, like I am replying to yours.  If you start a new message with
"Re:" it looks like a broken thread, not a new message.

Quote:
> Question  2 : Recursive Call & Stack
> =========================

> I'm learing some simple Interpreter technique, using expression-parsing,
> currenlty on
> win9x, and will port to Linux as well.

> Since expression parsing is using recursive call, and each call will use the
> stack space,

Many C implementations use a stack for this, but there is no such
thing as a stack defined by the C language itself, or no requirement
that one be used.

Quote:
> So I wondering If the program space have limited stack size , this will
> cause trouble if the stack
> space is not enough.

On implementations that use stacks, what size they are and whether you
can change that size is determined by the compiler and operating
system.  It is not defined by the language.

Quote:
> On MS-DOS
>    System stack space is fixed on config.sys , Program stack size ? depend
> on system stack ?

> On Win3.x
>   The window program need to declare the stack space used by the program.
> (myprog.def),
>   Still depend on Config.sys stack space allocation ?

> On Win32 (win95 and above)
>    However, the stack space (size) no need to be declared, so
>    I assume it is either dynamic allocated or somehow using other method for
> function call.

> On Unix
>    How is the stack allocated ? static or dynamic allocated by the system ?
>    How differ is it on different Unix (HP, Sun, System 5, Linux etc) ?

> Any Comment ?

> TQ,

>     Ng

Again, please learn how to post properly.  Signature blocks should
start with a line containing three characters, two dashes and a space,
like mine.

Questions about stack space and how to adjust it are 100%
implementation specific.  Since the C standard does not define or
require a stack, it most certainly does not provide any methods of
setting the size of one.

You need to ask these questions in either compiler specific or
operating system specific newsgroups, such as

But correct your subject lines and signature before you do.

Jack Klein
--
Home: http://jackklein.home.att.net
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.faqs.org/faqs/C-faq/learn/



Wed, 29 Jan 2003 03:00:00 GMT  
 Recursive call and Stack


Quote:

> Question  2 : Recursive Call & Stack

[snip]

This is OT, but...

As a general rule, if you think you are likely to overflow the stack, don't
use it.  Instead, implement a stack of your own, and dynamicly allocate
enough memory to handle it.  That way, you can gracefully handle any
situation where the computer is likely to run out of memory, and you don't
have to worry about how stack size is controlled on every platform in the
universe.

--Steve



Wed, 29 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Recursive functions and stack limitations

2. Help! Stack Overflow in Recursive

3. Question About A Recursive Stack Function

4. Help! Stack Overflow in Recursive

5. How to Prevent Stack Overflows with Recursive Routines?

6. prevent stack overflow in recursive function

7. Stack Overflow, with recursive function

8. destructor is called before copy-constructor on temporary class (allocated on stack during function call)

9. sibling and tail recursive calls

10. recursive call

11. Do static variables last through a recursive call?

12. Q: recursive call out of if()

 

 
Powered by phpBB® Forum Software