Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!research!dmr From: dmr@research.UUCP Newsgroups: net.lang.c Subject: setjmp: read the manual Message-ID: <1045@research.UUCP> Date: Thu, 4-Oct-84 01:03:04 EDT Article-I.D.: research.1045 Posted: Thu Oct 4 01:03:04 1984 Date-Received: Thu, 4-Oct-84 10:19:09 EDT Lines: 32 V7, 4.[01]BSD, and SVr0 manuals include this sentence in the setjmp/longjmp documentation (setjmp(3): "All accessible data have values as of the time longjmp was called." So setjmp shouldn't save register variables; they're irrelevant. That is, ... register x = 1; if (setjmp(sj_buf)) { printf("x = %d\n", x) exit(0); } x = 2; f(); } f() { longjmp(sj_buf, 1); } is supposed to print "x = 2" and longjmp is supposed to trace back in the stack to make sure this happens. (This is nontrivial, because the place where the register that contained x was saved can be anywhere in call chain.) There is a very good reason for doing it this way: it makes register and automatic variables behave the same. The specification could have said that data values are restored to those at the time that setjmp was called, but it doesn't (and shouldn't: that's a lot of stuff to save). I checked the behavior on V8, 4.2BSD, and SVr2. It works right (prints 2) on V8 and 4.2, works wrong (prints 1) on SV (on VAX, 3B20, 3B2). I don't have 4.2 or SVr2 manuals at hand so I don't know what they say. Dennis Ritchie