Restores the environment to the state indicated by env, evaluating the setjmp expression that filled env as val.
The function never returns to the point where it has been invoked. Instead, the function transfers the control to the point where setjmp was last used to fill the env, and evaluates the whole expression as val (unless this is zero, in which case it evaluates as value of 1).
If env was not filled by a previous call to setjmp or if the function with such call has terminated execution, it causes undefined behavior.
In C++, the implementation may perform stack unwinding that destroys objects with automatic duration. If this invokes any non-trivial destructors, it causes undefined behavior.
Object of type jmp_buf filled by a previous call to setjmp that contains information to restore the environment to that point.
Value to which the setjmp expression evaluates.
If this is zero, the expression evaluates as 1.
none (the function never returns).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* longjmp example */
#include <stdio.h> /* printf */
#include <setjmp.h> /* jmp_buf, setjmp, longjmp */
printf ("val is %d\n",val);
if (!val) longjmp(env, 1);
val is 0
val is 1
The scope of the setjmp and longjmp pair is limited to the current thread.
If no automatic objects with non-trivial destructors are involved in the potential stack unwinding, this function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior.