> > > How can you do a non-trivial program with recursion without stack
> > > overflow?
> >
> > Very carefully, but it can happen.
>
> In anything resembling real world, a FOR loop works better. I've used
> recursion ... but the stack load was excessive. In order for
> recursion to be stable, one would want more than a 64K segment for
> stack.
Yes, a 64K stack segment could be a problem! Don't dismiss recursion in
real-world projects entirely, though. If you can prove that there will be
enough stack space, if you actually need to use a full address width to
record the previous execution location, and if it is more elegant code,
then you've got to seriously consider it. How likely is that? Not very.
But it is possible. I ran into such a situation when writing a parser (in
a real-world project) a few months back.
> > > while(*T++=*S++);
> >
> > Was this an actual program fragment?
>
> Yes. It's how C copies a string. ...
Oh, I know that. I was just astonished they'd be doing stuff like that in
an 'introductory' course.
--
Jeffrey S. Sharp
jss_at_subatomix.com
Received on Mon Aug 20 2001 - 21:26:56 BST