Path: utzoo!attcan!uunet!mcvax!ukc!warwick!geoff From: geoff@warwick.UUCP (Geoff Rimmer) Newsgroups: comp.lang.c Subject: Re: Behaviour of setjmp/longjmp and registers Message-ID: <947@ubu.warwick.UUCP> Date: 23 Jan 89 14:49:03 GMT References: <25@torsqnt.UUCP> Sender: news@warwick.UUCP Reply-To: geoff@emerald.UUCP (Geoff Rimmer) Organization: Computer Science, Warwick University, UK Lines: 45 In article <25@torsqnt.UUCP> david@torsqnt.UUCP (David Haynes) writes: >What should be the result of running the following program? > >#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? I don't know what the ANSI standard says, but our manual page for setjmp() mentions in passing that register variables have unpredictable values code after the return from longjmp So, it's probably just luck that the Sequent, Ultrix and Vax C compiler give what you'd expect from a non-register variable: j = 1, j = 4 Geoff ------------------------------------------------------------ Geoff Rimmer, Computer Science, Warwick University, England. geoff@uk.ac.warwick.emerald "Oo, have we got a video?" "If anyone else asks me that question, I'm going to put head through the window." - The Young Ones, 1984 (?) ------------------------------------------------------------