Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
jmp_buf buf;

void f(void) {
  volatile int i = 10;
  if (setjmp(buf) == 0) {
    printf("i = %d\n", i);
  } else {
    printf("longjmp: i = %d\n", i);
    exit(0);
  }
  h();
  return;
}

void h(void) {
  char b[16];
  memset(b, 0, 16);
  longjmp(buf, 1);
}

Implementation Details

In this example there is no risk of overwriting i because the stackframe of f() is still on the stack, so when h is invoked, the two stackframes will not overlap.

...