Restores processor state saved by setjmp().
#include <setjmp.h> int setjmp(jmp_buf env);
env
The current processor state.
val
A non-zero value that setjmp() will return.
The setjmp() function saves the calling environment in the env argument. The argument must be initialized by setjmp() before being passed as an argument to longjmp().
When it is first called, setjmp() saves the processor state and returns 0. When longjmp() is called program execution jumps to the setjmp() that saved the processor state in env. When activated through a call to longjmp(), setjmp() returns longjmp()'s val argument.
This facility may not be available on some configurations of the EWL.
#include <setjmp.h> #include <stdio.h> #include <stdlib.h> /* Let main() and doerr() both have * access to env. */ volatile jmp_buf env; void doerr(void); int main(void) { int i, j, k; printf("Enter 3 integers that total less than 100.\n"); printf("A zero sum will quit.\n\n"); /* If the total of entered numbers is not less than 100, * program execution is restarted from this point. */ if (setjmp(env) != 0) printf("Try again, please.\n"); do { scanf("%d %d %d", &i, &j, &k); if ( (i + j + k) == 0) break; printf("%d + %d + %d = %d\n\n", i, j, k, i+j+k); if ( (i + j + k) >= 100) doerr(); /* Error! */ } while (1); /* loop forever */ return 0; } void doerr(void) { printf("The total is >= 100!\n"); longjmp(env, 1); } Output: Enter 3 integers that total less than 100. A zero sum will quit. 10 20 30 10 + 20 + 30 = 60 -4 5 1000 -4 + 5 + 1000 = 1001 The total is >= 100! Try again, please. 0 0 0