Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Behaviour of setjmp/longjmp and registers Message-ID: <1989Jan23.005859.24468@utzoo.uucp> Organization: U of Toronto Zoology References: <25@torsqnt.UUCP> <8867@bloom-beacon.MIT.EDU> <7222@polyslo.CalPoly.EDU> Date: Mon, 23 Jan 89 00:58:59 GMT In article <7222@polyslo.CalPoly.EDU> cquenel@polyslo.CalPoly.EDU (96 more school days) writes: >Assuming that volatile variables are written out to memory >before any procedure call. (Even if this is not sufficient, >assume that volatile variables have been dealt with.) > >Should it ever be necessary/desirable to restore any registers >on a long-jump BESIDES the frame-pointer and/or stack-pointer ? Assuming that any other registers needed by the compiler -- not all implementations get by with just an FP and SP -- have been dealt with, ANSI C conformance doesn't require anything more. However, an implementation that simply trashes the registers (rather, allows them to be trash) or, still worse, does likewise for automatic variables not declared "register" (i.e. by promoting them to registers and then not preserving them), is probably not going to sell well when word gets around. The old de-facto rule was that register variables had either current values or values as of the setjmp call, and that other automatics weren't touched at all. Minimal ANSI conformance will thus break essentially every longjmp-using program in existence. Don't expect the customers to be too delighted about that. Your best quick solution is to save all registers at setjmp time and then restore them at longjmp time, and avoid promoting automatic variables. The preferred solution, more work, is to notice the use of setjmp (there are enough restrictions on it that you can do that) and save/restore everything around all function calls within a function that uses setjmp. -- Allegedly heard aboard Mir: "A | Henry Spencer at U of Toronto Zoology toast to comrade Van Allen!!" | uunet!attcan!utzoo!henry henry@zoo.toronto.edu