Behaviour of setjmp/longjmp and registers

Andrew Koenig ark at alice.UUCP
Thu Jan 26 04:10:44 AEST 1989


In article <9467 at ihlpb.ATT.COM>, gregg at ihlpb.ATT.COM (Wonderly) writes:

> It strikes me that setjmp() could save all GP registers.  I know of at
> least one implementation were a jmp_buf is enough space for the entire
> register set.  longjmp() of course just reloads the registers grabs the
> return value passed, and jumps to the return address given to it (on the
> stack or elsewhere).  The expense is a consideration but the results are
> guaranteed in the cases I can think of.

Yup, that's what the folks thought who did the first VAX
implementation, too.

It doesn't work.  Consider this case:

	register x;
	jmp_buf j;

	x = 3;
	if (setjmp(j))
		{ stuff }
	x = 4;
	longjmp(j,1);

You will see that when `stuff' is executed, x will have been
restored to 3.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list