setjmp: read the manual(long article)

george at idis.UUCP george at idis.UUCP
Fri Oct 26 02:53:07 AEST 1984


I suggest that anyone seriously interested in setjmp/longjmp
read the section titled "unwinding" from BTL CSTR #102,
"The C Language Calling Sequence", by S. C. Johnson and D. M. Ritchie.
Perhaps Dennis Ritchie could post that section.

If anyone is going to implement a routine that has behavior
different from "longjmp" (as described in the tech. report
or UNIX V7 manuals) then it would be prudent to name it
something other than "longjmp".

Hans van Staveren wrote:

>	     General solution, all machines, Amsterdam Compiler Kit:
			...
>	Well here it is.  Have the  C-frontend  recognize  the  word
>	setjmp.   In a function containing a call to setjmp save all
>	registers, use none, and at the end restore  them  all.   At
>	longjmp  time  just  close  your eyes and jump, no registers
>	need be restored except the frame pointer, stack pointer and
>	program  counter.   This  means  that  functions  not  using
>	setjmp/longjmp are not bothered, in general the compiler can
>	continue  its  fancy register optimizations and all programs
>	will run correct.

There is a minor problem with this.
Since one can have an undefined extern pointer to a function,
or a pointer to a function passed as an argument,
one may need to pessimize all calls from some functions
that do not explicitly call "setjmp".
Thus contrary to what Hans claimed,
some functions not using setjmp/longjmp are bothered.
Presumably these do not occur too frequently in practice.
Some programs not using setjmp/longjmp are also bothered.
(I also believe I have heard that the Amsterdam compilers can cheat
by looking at the source for undefined extern objects,
although I do not know if it does so in the above instances.)


		George Rosenberg
		duke!mcnc!idis!george
		decvax!idis!george



More information about the Comp.lang.c mailing list