Behaviour of setjmp/longjmp and registers
Andrew Koenig
ark at alice.UUCP
Mon Jan 23 02:15:56 AEST 1989
In article <7222 at polyslo.CalPoly.EDU>, cquenel at polyslo.CalPoly.EDU (96 more school days) writes:
> Should it ever be necessary/desirable to restore any registers
> on a long-jump BESIDES the frame-pointer and/or stack-pointer ?
No, unfortunately.
Once upon a time, the VAX setjmp worked by saving all the
registers in the jmp_buf and longjmp restored it. That means
that if you say:
register foo;
jmp_buf jb;
foo = 3;
if (setjmp(jb)) {
/* exception stuff */
}
foo = 7;
func();
and func calls longjmp(jb), foo will be 3 and not 7 when the
`exception stuff' is executed.
John Reiser figured out a way around it -- a nifty version of
longjmp that unwound the stack, restoring the correct registers
at each iteration -- and that went into at least some VAX C
implementations.
However, when it came to the ANSI committee, they decided it
would be too hard to mandate this kind of implementation.
So they took the least restrictive route possible -- longjmp
doesn't have to work at all unless you beg it.
--
--Andrew Koenig
ark at europa.att.com
More information about the Comp.lang.c
mailing list