Path: utzoo!attcan!uunet!ncrlnk!ncr-sd!hp-sdd!ucsdhub!sdcsvax!ucsd!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Behaviour of setjmp/longjmp and registers Message-ID: <8831@alice.UUCP> Date: 25 Jan 89 18:10:44 GMT References: <5771@phoenix.Princeton.EDU> <9467@ihlpb.ATT.COM> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 28 In article <9467@ihlpb.ATT.COM>, gregg@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@europa.att.com