Behaviour of setjmp/longjmp and registers

Steve Summit scs at adam.pika.mit.edu
Sat Jan 21 16:37:15 AEST 1989


Here are my rules for using setjmp/longjmp and remembering which
variables are preserved:

     1.	Never use setjmp and longjmp.

     2.	If rule 1 must be broken, do not depend on the values of
	any variables after setjmp has "returned" due to a call
	to longjmp.

These rules are admittedly conservative, but as long as I follow
them I never have problems with setjmp or longjmp or which
variables are preserved.  I believe I have broken rule 1 twice; I
have had problems with variable preservation approximately 50% of
those times.  Therefore I conclude that rule 1 is a good rule.

                                            Steve Summit
                                            scs at adam.pika.mit.edu

Ten people will now sanctimoniously flame me, saying that the
problem is not with setjmp/longjmp but with my (lack of)
understanding of them.  Save it.  I could remember the details
and rationale of the variable preservation rules if I wanted to.
Since I consider longjmp an abysmal idea in the first place, and
I have been able to get along without it virtually all of the
time, I don't choose to keep my knowledge on it current.  It is
also unnecessary to point out to me all of the cases where
longjmp has been found indispensable; I'm familiar with the
arguments.



More information about the Comp.lang.c mailing list