Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!pasteur!ucbvax!agate!bionet!csd4.milw.wisc.edu!mailrus!wasatch!cdr.utah.edu!moore From: moore%cdr.utah.edu@wasatch.UUCP (Tim Moore) Newsgroups: comp.lang.c Subject: Re: Behaviour of setjmp/longjmp and registers Message-ID: <944@wasatch.UUCP> Date: 20 Jan 89 21:21:19 GMT References: <25@torsqnt.UUCP> Sender: news@wasatch.UUCP Reply-To: moore%cdr.utah.edu.UUCP@wasatch.UUCP (Tim Moore) Organization: University of Utah, Computer Science Dept. Lines: 36 In article <25@torsqnt.UUCP> david@torsqnt.UUCP (David Haynes) writes: #include main() { register int j; jmp_buf env; j = 1; if(setjmp(env) == 1) { printf("j = %d\n", j); exit(1); } printf("j = %d\n", j); j += 3; longjmp(env, 1); } Sequent, Ultrix and Vax C give results of j = 1, j = 4. Gcc gives a result of j = 1, j = 1. What does the ANSI standard say about this? -david- Gcc follows the ANSI standard which, when strictly interpreted, says that "the only automatic variables guaranteed to remain valid are those declared volatile" (quoted from the gcc manual). Traditional compilers put local variables in the stack in functions that call setjump. If you look at the assembly code output of Sequent, Ultrix, Vax C, and gcc with the "-traditional" flag you will see that j isn't really being stored in a register. -Tim Moore 4560 M.E.B. internet:moore@cs.utah.edu University of Utah ABUSENET:{ut-sally,hplabs}!utah-cs!moore Salt Lake City, UT 84112