At 11:10 PM +0900 8/8/03, Brian Candler wrote:
>On Fri, Aug 08, 2003 at 10:26:26PM +0900, djd15 / cwru.edu wrote:
>  > I think this makes callcc a bit different than
>  > setjmp and longjmp from C (although I haven't used
>>  them, only read about them), as I believe they make
>>  a copy of, and restore the stack.
>
>I don't think so; AFAIK setjmp just stores the stack pointer and instruction
>pointer (and other registers, I guess), and longjmp just restores them. C is
>only portable machine-code, after all :-)
>
>As a result, at longjmp the stack is "wound back" to exactly where it was
>before. Any local variables declared within nested function calls are
>therefore lost. But any variables declared within the current function, or
>in functions which call it, or global variables, keep their current values.

More exactly, after a longjmp the stack *pointer* is put back to 
where it was before. (As are all the registers, generally) This is 
why longjmp is only OK to do upwards--once you exit the function that 
did the setjmp, parts of the stack that longjmp will expose will have 
been reused. Which, while occasionally useful for *very* evil code, 
is normally a really fatal thing.
-- 
                                         Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan / sidhe.org                         have teddy bears and even
                                       teddy bears get drunk