Path: utzoo!attcan!uunet!husc6!uwvax!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: <8812@alice.UUCP> Date: 22 Jan 89 16:15:56 GMT References: <25@torsqnt.UUCP> <8867@bloom-beacon.MIT.EDU> <7222@polyslo.CalPoly.EDU> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 36 In article <7222@polyslo.CalPoly.EDU>, cquenel@polyslo.CalPoly.EDU (96 more school days) writes: > Should it ever be necessary/desirable to restore any registers > on a long-jump BESIDES the frame-pointer and/or stack-pointer ? No, unfortunately. Once upon a time, the VAX setjmp worked by saving all the registers in the jmp_buf and longjmp restored it. That means that if you say: register foo; jmp_buf jb; foo = 3; if (setjmp(jb)) { /* exception stuff */ } foo = 7; func(); and func calls longjmp(jb), foo will be 3 and not 7 when the `exception stuff' is executed. John Reiser figured out a way around it -- a nifty version of longjmp that unwound the stack, restoring the correct registers at each iteration -- and that went into at least some VAX C implementations. However, when it came to the ANSI committee, they decided it would be too hard to mandate this kind of implementation. So they took the least restrictive route possible -- longjmp doesn't have to work at all unless you beg it. -- --Andrew Koenig ark@europa.att.com