Volatile is Necessary

Eric Bergan eric at pyrps5
Thu Mar 31 10:41:22 AEST 1988


In article <1259 at PT.CS.CMU.EDU>, jgm at 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.



More information about the Comp.lang.c mailing list