Path: utzoo!mnetor!uunet!husc6!mailrus!ames!oliveb!pyramid!eric From: eric@pyrps5 (Eric Bergan) Newsgroups: comp.lang.c Subject: Re: Volatile is Necessary Message-ID: <17982@pyramid.pyramid.com> Date: 31 Mar 88 00:41:22 GMT Sender: daemon@pyramid.pyramid.com Lines: 29 In article <1259@PT.CS.CMU.EDU>, jgm@K.GP.CS.CMU.EDU (John Myers) writes: > > Is R. Stallman's reading of the ANSI draft wrong, or isn't it > necessary to declare automatic variables as 'volatile' in order to > guarantee that their values will be preseved across a setjmp/longjmp? > (as otherwise they could be placed in registers) > > If RMS is right, then the committee botched setjmp/longjmp. I'm jumping into the middle of this argument, so please forgive me if this has been already stated. I think there are more serious problems with setjmp/longjmp than just the volatile issues of variables. There is also the problem of common subexpressions kept in temporary registers spanning the setjmp call. While perhaps far-fetched, it is possible to think of expressions consisting solely of automatic variables that are provably non-aliased, so that they would not be invalidated by a procedure call (such as setjmp), and common subexpressions of these that might be kept in registers, for use inside the body of the setjmp block. Clearly, when longjmp jumps into this, these temporary registers will probably no longer contain the expected subexpressions, and the code within the setjmp block will fail. My guess is that some kind of declaration of setjmp itself is necessary, to let the compiler know that nothing can be trusted across this function call. Either that, or a true exception handling mechanism for C that doesn't completely invalidate modern optimizers.