Mail Archives: djgpp/1998/03/16/06:30:24
On Fri, 13 Mar 1998, Anthony.Appleyard wrote:
> What the rules for deciding whether longjmp may `clobber' a particular local
> variable or a `*this'? (I never use vfork().)
This is clearly explained in the GCC manual (type "info gcc invoking
warning" and search for ``longjmp''):
* A nonvolatile automatic variable might be changed by a call to
`longjmp'. These warnings as well are possible only in
optimizing compilation.
The compiler sees only the calls to `setjmp'. It cannot know
where `longjmp' will be called; in fact, a signal handler
could call it at any point in the code. As a result, you may
get a warning even when there is in fact no problem because
`longjmp' cannot in fact be called at the place which would
cause a problem.
The problem is that GCC assumes that any local variable not declared
`volatile' may be clobbered. `longjmp' restores the stack state to
what `setjmp' has recorded, but depending on where was the local
variable stored (in a register, on the stack, or in memory) when
`longjmp' is called, you may or may not get it restored.
The easiest solution is to declare the variable `volatile' (and have
some sub-optimal optimization). Or just live with the warning.
- Raw text -