Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site alice.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: net.unix-wizards Subject: Steve Rosen's setjmp problem Message-ID: <3826@alice.UUCP> Date: Fri, 7-Jun-85 00:20:16 EDT Article-I.D.: alice.3826 Posted: Fri Jun 7 00:20:16 1985 Date-Received: Fri, 7-Jun-85 05:23:02 EDT Organization: Bell Labs, Murray Hill Lines: 30 Steve Rosen complains that the following C program fails: #include static jmp_buf env; int mode; main(){ foo(); longjmp(env, 1); } foo(){ mode = setjmp(env); if (mode != 0) magic(); } magic() { printf("HERE I AM\n"); exit(0); } The reason the program fails is that foo returns after calling setjmp. This destroys the environment that setjmp saved, so there is nothing for longjmp to return to. General rule: every call to longjmp must be made from a function that is a dynamic descendent of the one that made the corresponding call to setjmp.