Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 exptools 1/6/84; site ihldt.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxj!ihnp4!ihldt!bwf From: bwf@ihldt.UUCP (Bill Fecht) Newsgroups: net.lang.c Subject: Re: Re: What is the setjump call Message-ID: <2528@ihldt.UUCP> Date: Mon, 1-Oct-84 10:38:36 EDT Article-I.D.: ihldt.2528 Posted: Mon Oct 1 10:38:36 1984 Date-Received: Wed, 3-Oct-84 19:19:55 EDT Organization: AT&T Bell Labs, Naperville, IL Lines: 40 Careful, the setjmp() call saves only a few registers and stack pointers, it does not save the stack. Not understanding this could cause two problems: 1) thinking that a longjmp() will restore automatic variables, i.e. #includejmp_buf jb; main() { int x; x = 1; setjmp(jb); if (x == 2) { printf("bailout\n"); exit(); } x = 2; longjmp(jb); } 2) thinking that a longjmp() will restore calling sequence, i.e. jmp_buf jb; foo1() { foo2(); bar(); } foo2() { foo3(); } foo3() { setjmp(jb); } bar() { longjmp(jb); } Also, you should use 'jmp_buf jb', NOT 'char[8] jb' (:-)), 'jmp_buf' will reserve all you need to do the setjmp()/longjmp(). I think setjmp() and longjmp() were included in Unix to recover from convoluted nesting in the event of errors, then were included in C for the user, I think. I know uucp uses the mechanism for this a lot. bill (ihack!bwf) fecht