next up previous contents index
Next: Restore calling environment Up: Save calling environment Previous: Save calling environment

The setjmp macro

One proposed requirement on setjmp is that it be usable like any other function --- that it be callable in any expression context, and that the expression evaluate correctly whether the return from setjmp is direct or via a call to longjmp. Unfortunately, any implementation of setjmp as a conventional called function cannot know enough about the calling environment to save any temporary registers or dynamic stack locations used part way through an expression evaluation. (A setjmp macro seems to help only if it expands to inline assembly code or a call to a special built-in function.) The temporaries may be correct on the initial call to setjmp, but are not likely to be on any return initiated by a corresponding call to longjmp. These considerations dictated the constraint that setjmp be called only from within fairly simple expressions, ones not likely to need temporary storage.

An alternative proposal considered by the Committee is to require that implementations recognize that calling setjmp is a special case,gif and hence that they take whatever precautions are necessary to restore the setjmp environment properly upon a longjmp call. This proposal was rejected on grounds of consistency: implementations are currently allowed to implement library functions specially, but no other situations require special treatment.

4 6 2


Pete Jinks
Fri Jan 19 12:31:56 GMT 1996