Related articles |
---|
setjmp and volatile local vars richard@viz.tamu.edu (Richard Henderson) (1994-03-06) |
Newsgroups: | comp.compilers |
From: | Richard Henderson <richard@viz.tamu.edu> |
Keywords: | C, optimize |
Organization: | Compilers Central |
Date: | Sun, 6 Mar 1994 21:32:33 GMT |
A bit ago our moderator asked if simply saving local variables
to the stack across function calls in the presence of setjmp
ever got you in trouble.
The answer is of course, yes. You can longjmp from a signal
handler without having called another function.
For example:
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
jmp_buf jb;
void handlesig()
{
longjmp(jb);
}
int main()
{
int x = 1;
if (setjmp(jb))
{
printf("x = %d\n", x);
exit(0);
}
else
{
signal(SIGALRM, handlesig);
alarm(1);
x = 2;
while (1)
continue;
}
}
richard~
--------
Richard Henderson
richard@viz.tamu.edu
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.