|
jmp_buf type | Jump buffer |
typedef . . . jmp_buf ; |
The jmp_buf type is an opaque array type that stores information for the setjmp and longjmp functions.
longjmp function | Performs nonlocal goto |
void longjmp (jmp_buf env, int val); |
The longjmp function bypasses the normal function return and unwinds the call stack to the point where setjmp was called with the same jmp_buf environment. When setjmp returns to its caller, it returns val ; if val is , setjmp returns 1 .
Calling longjmp is similar to throwing an exception that is caught at the point of the setjmp call. One important difference, however, is that if any objects on the stack would have been destroyed by throwing an exception, the program's behavior is undefined if you call longjmp . This is why you should use exceptions instead of longjmp .
setjmp function | Establishes nonlocal label |
int setjmp (jmp_buf env); |
The setjmp function stores the current execution environment in its argument so that the environment can be restored by a call to longjmp . The first time setjmp is called, it returns . When longjmp is called, setjmp returns the val argument that was passed to longjmp ; that value is guaranteed to be nonzero.