[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: re-entrant programs



dockery@griffin.cuc.ab.ca (Sean Dockery) writes:

>Wouldn't this be as easy as having the initialization stage of the
>routine save the old values of the variables in an internal buffer or
>external stack, and restores the previous values when it reaches the
>end of the routine?

If you want to use an internal buffer, it wouldn't work because if your
routine got called again, the buffer would contain variables from two
executions up and you wouldn't want to overwrite it with stuff from one
execution up.

If you're talking about saving those old values on the stack, then you've
just defined a recursive, reentrant routine! It's not the best way of doing
recursion, but it works, and to answer your question "Wouldn't it be as easy as
having...", well, yes, it would be that easy. :)

>I have previously implemented this inside some of my programs.  Oh,
>well.  I guess it was bound to happen.  (Never mind: it's an inside
>joke going around my programming group about me re-inventing the
>wheel.)

That's good. That means you're at least as smart as the pioneers of computing
who invented it first :)

>sean
>-- 
># internet: dockery@griffin.cuc.ab.ca   | "alone.  death can't hold a candle
>#      -or- dockery@pro-calgary.cts.com |  to it, and hell is a poor synonym"
># pro-line: dockery@pro-calgary         |                       -stephen king
>#     uucp: crash!pro-calgary!dockery   | disclaimer: i am unemployed
 ______________________________________________________________________
|~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Phillip Vandry | Vandry@Cam.Org | Merry Christmas II you!            |
|________________|________________|____________________________________|
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~