Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!genrad!mit-eddie!godot!ima!ISM780B!jim From: jim@ISM780B.UUCP Newsgroups: net.lang.c Subject: Re: setjmp(), register vars and the prop Message-ID: <111@ISM780B.UUCP> Date: Sat, 3-Nov-84 12:40:04 EST Article-I.D.: ISM780B.111 Posted: Sat Nov 3 12:40:04 1984 Date-Received: Sun, 4-Nov-84 04:45:13 EST Lines: 43 Nf-ID: #R:tekecs:-414200:ISM780B:25500061:000:1702 Nf-From: ISM780B!jim Oct 31 19:04:00 1984 >/* Written 3:30 pm Oct 31, 1984 by peterg@tekecs in ISM780B:net.lang.c */ >/* ---------- "setjmp(), register vars and the prop" ---------- */ >This is how the library subsection of the proposed ANSI standard >reads for setjmp()/longjmp(): > >> All accessible objects have value as of the time longjmp was called, >> except for objects of storage class auto or register whose values >> have been changed between the setjmp and longjmp calls. These values >> are undefined. > >Given that many processors don't automatically push any kind of register >mask on the stack (as VAXen do) this seems like a 'safe and sane' approach. I assume the restriction on auto variables is to allow compilers to keep them in registers part or all of the time. I think the restriction should only be to variables of the routine that called setjmp, and to modifications made within that routine, so that there is no implication that in foo() { int x; bar(&x); ...} bar(xp) int *x; {int y; *xp = 3; setjmp(jmpbuf); crud(&y); ...} or the value of y is undefined after the longjmp if it was modified by crud, or that the value of x is undefined after the longjmp. For complete safety, I suggest that setjmp and longjmp be used only in the following fashion: if( setjmp(jmpbuf) == 0 ) abortablefunc(...); else ... where longjmp will only be called as a descendant of abortablefunc. This is much more structured and understandable than arbitrary global jumps. It guarantees that no local variables are changed between the time of the setjmp and the longjmp (barring side effects in the evaluation of abortablefunc's args, e.g., abortablefunc(a = b, *p++)). -- Jim Balter, INTERACTIVE Systems (ima!jim)