setjmp and volatile local vars

Richard Henderson <>
Sun, 6 Mar 1994 21:32:33 GMT

          From comp.compilers

Related articles
setjmp and volatile local vars (Richard Henderson) (1994-03-06)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Richard Henderson <>
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()

int main()
        int x = 1;
        if (setjmp(jb))
printf("x = %d\n", x);
signal(SIGALRM, handlesig);

x = 2;
while (1)

Richard Henderson

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.