setjmp/longjmp

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Mon Oct 29 13:01:16 AEST 1984


> I see in previous articles enough information to convince me that we can't
> ask that all local variables by restored in longjmp to their values at the
> time of the setjmp, or to their last value in the routine containing the
> setjmp.  If there is a way to achieve this that is affordable, I'd far
> prefer it to my proposal.
> 
> So the problem comes down to characterizing which variables will be
> restored, and which will have random values.  I propose that only
> variables not altered since the setjmp call be guaranteed restored; other
> variables will have random values (not necessarily their last set value,
> the value they had at the time of the setjmp, or anything else).
> This is obviously achievable by simply saving and restoring all registers
> at setjmp/longjmp; on some hardware considerable improvements in this can
> be made.  
> 
> So, is this enough to be useful?  And, is more achievable transportably?

I agree with Dennis Ritchie that longjmp should resume after the call
to setjmp with all accessible data containing values as of the time of
the longjmp.  This can always be implemented, although some C run-time
designs seem to have not saved enough information on the call stack to
support longjmp.  Such implementations need to be changed.  Any system
where a subroutine call saves all the non-scratch registers (e.g., PDP-11,
Gould) is in good shape, as is any system where the number of registers
actually saved is recorded in the call frame (e.g. VAX).  Other systems
may have to have their calling sequences re-engineered, but that is what
they deserve for taking shortcuts.



More information about the Comp.lang.c mailing list