restore the environment saved by setjmp
#include <setjmp.h> void longjmp( jmp_buf env, int return_value );
The longjmp() function restores the environment saved by the most recent call to the setjmp() function with the corresponding env argument.
It is generally a bad idea to use longjmp() to jump out of an interrupt function or a signal handler (unless the signal was generated by the raise() function).
After the longjmp() function restores the environment, program execution continues as if the corresponding call to setjmp() had just returned the value specified by return_value. If the value of return_value is 0, the value returned is 1.
#include <stdio.h> #include <setjmp.h> jmp_buf env; rtn() { printf( "about to longjmp\n" ); longjmp( env, 14 ); } void main() { int ret_val = 293; if( 0 == ( ret_val = setjmp( env ) ) ) { printf( "after setjmp %d\n", ret_val ); rtn(); printf( "back from rtn %d\n", ret_val ); } else { printf( "back from longjmp %d\n", ret_val ); } }
produces the following:
after setjmp 0 about to longjmp back from longjmp 14
ANSI
All (except DOS/PM)