From: Richard Henderson <rth@dot.cygnus.com>
Subject: Re: gcc compiler warning
Date: Mon, 23 Feb 1998 16:31:43 -0800 [thread overview]
Message-ID: <35390bbbdd8b709f09d36bc834099340.axp-list@archive.invalid> (raw)
In-Reply-To: <199802231437.JAA04904@rrdjazz.nist.gov>
On Mon, Feb 23, 1998 at 09:37:14AM -0500, Przemek Klosowski wrote:
> Register-based local variables are not guaranteed to be preserved
> across longjump (and also I guess vfork); in other words if you do
> setjmp, and then longjmp to it, you aren't guaranteed to see the
> values of register-based local variables as they were at time of
> setjmp; this is because setjmp/longjmp save/restore the stack only.
No, the real problem is that longjmp _does_ restore the call-saved
registers to the contents they had at setjmp, when what is wanted
is a real stack-unwind as is possible when the language supports
exceptions. So in
jmp_buf buf;
register int i = 1;
if (setjmp(buf))
printf("%d\n", i);
else
{
i = 10;
longjmp(buf, 1);
}
if i is allocated to a call-saved register, you get 1, if not,
you get 10. The warning reminds you that that the only way to
get consistent results is to declare i volatile. In which case
you get 10.
r~
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
next prev parent reply other threads:[~1998-02-24 0:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-02-23 14:37 gcc compiler warning Przemek Klosowski
1998-02-24 0:31 ` Richard Henderson [this message]
-- strict thread matches above, loose matches on Subject: below --
1998-02-23 8:07 Jim. Shipman
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox