Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site uthub.UUCP Path: utzoo!utcsrgv!utai!uthub!thomson From: thomson@uthub.UUCP (Brian Thomson) Newsgroups: net.lang.c Subject: Re: What is the setjump call Message-ID: <179@uthub.UUCP> Date: Mon, 1-Oct-84 11:45:20 EDT Article-I.D.: uthub.179 Posted: Mon Oct 1 11:45:20 1984 Date-Received: Mon, 1-Oct-84 13:49:48 EDT References: <220997c8.8e4@apollo.uucp> Organization: CSRG, University of Toronto Lines: 33 Kee Hinckley almost gets it right: > Setjump stores the current state of the stack and any relevant > registers and hands them back to the program to hang onto. At some > later date the program can then call longjmp and everything will > return to the state of the machine at the time of the setjump. In fact, a correct setjmp/longjmp implementation doesn't just store and restore register contents. Rather, longjmp() should do a 'deep return', restoring registers only if they have been salted away as part of normal program execution. In particular, the program jmp_buf env; main() { register int i; i = 0; if(setjmp(&env)) { printf("%d\n", i); exit(0); } i = 1; longjmp(&env, 1); } should print 1, not 0. Check the manual page -- ours (4.2) says "All accessible data have values as of the time longjmp was called." Note that, with this definition, the behaviour of a variable is independent of whether it was declared "register". -- Brian Thomson, CSRI Univ. of Toronto {linus,ihnp4,uw-beaver,floyd,utzoo}!utcsrgv!uthub!thomson