setjmp/longjmp
Jeff Collins
jeff at Alliant.COM
Fri May 5 00:56:23 AEST 1989
In article <1447 at cunixc.cc.columbia.edu> fuat at cunixc.cc.columbia.edu (Fuat C. Baran) writes:
>someone could explain the idea behind the behaviour we are
>experiencing on the Encore (i.e. why can't automatic variables be
>modified after the setjmp such that they retain their value after the
>longjmp back)? I looked at the man pages for a couple of compilers
>that sort of are "Draft ANSI"ish and this point is in general not
>explained clearly.
>
When the setjmp is first invoked, the current register state is saved,
in the jmpbuf array. This register state includes the current values
of automatic variables. When the subsequent longjmp is called, the
state restored in the jmpbuf array is restored, including the register
set. This means that any changes to automatic variables after the
setjmp are "overwritten", because the register that stores the
variable is restored to its value before the setjmp. There is no way
that setjmp/longjmp can handle this problem, as they do not know which
automatic variable are "going to possibly change sometime in the future.
The rule when dealing with setjmp/longjmp and an optimizing compiler
(ie. one that makes heavy use of registers, like Encore's), is to
force the variable in question to not be in a register.
More information about the Comp.std.c
mailing list