setjmp: read the manual

darryl at ism780.UUCP darryl at ism780.UUCP
Wed Oct 17 14:19:20 AEST 1984


>> V7, 4.[01]BSD, and SVr0 manuals include this sentence in the setjmp/longjmp
>> documentation (setjmp(3): "All accessible data have values as of the time
>> longjmp was called."  ...  (This is nontrivial, because the
>> place where the register that contained x was saved can be anywhere in
>> call chain.)
>>
>> There is a very good reason for doing it this way: it makes
>> register and automatic variables behave the same.
>>
>There's a good reason for doing it the other way: efficiency.  The Sun
>(4.2 on 68010's) setjmp(3) says:
>
>       "All memory-bound data have values as of the time longjmp was called.
>        The machine registers are restored to the values they had at the time
>        setjmp was called.  But, because the register storage class is
>        only a hint to the C compiler, variables declared as register
>        variables may not necessarily be assigned to machine registers,
>        so their values are unpredictable after a longjmp.  This is
>        especially a problem for programmers trying to write machine-
>        independent C routines."

Gee, wouldn't it be easier to just make your jmp_buf big enough to hold all
of the registerable registers and save them at setjmp time and restore them
at longjmp?  Then they would retain their values as of setjmp...

	    --Darryl Richman
	    ...!cca!ima!ism780!darryl



More information about the Comp.lang.c mailing list