A function that restores the environment saved by
setjmp
.
Include
<setjmp.h>
Prototype
void longjmp(jmp_buf env, int val);
Arguments
env
val
Remarks
The value parameter, val
, should be non-zero. If
longjmp
is invoked from a nested signal handler (that is, invoked
as a result of a signal raised during the handling of another signal), the behavior is
undefined.
Example
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
jmp_buf jb;
void inner (void)
{
longjmp(jb, 5);
}
int main (void)
{
int i;
if(i = setjmp(jb)) {
printf("setjmp returned %d\n" i);
exit(0);
}
printf("setjmp returned 0 - good\n");
printf("calling inner...\n");
inner();
printf("inner returned - bad!\n");
}
Example Output
setjmp returned 0 - good
calling inner...