9.7 Nonlocal Jumps (<setjmp.h>)

The <setjmp.h> header file contains declarations that provide a way to avoid the normal function call and return sequence, typically to permit an intermediate return from a nested function call.

Macro

int setjmp(jmp_buf env)


Sets up the local jmp_buf buffer and initializes it for the jump (the jump itself is performed with longjmp .) This macro saves the program's calling environment in the environment buffer specified by the env argument for later use by the longjmp function. If the return is from a direct invocation, setjmp returns 0. If the return is from a call to longjmp , setjmp returns a nonzero value.

Type

jmp_buf


An array type suitable for holding the information needed to restore a calling environment.

Function

void longjmp(jmp_buf env, int value;)


Restores the context of the environment buffer env that was saved by invocation of the setjmp function in the same invocation of the program. The longjmp function does not work if called from a nested signal handler; the result is undefined.

The value specified by value is passed from longjmp to setjmp . After longjmp is completed, program execution continues as if the corresponding invocation of setjmp had just returned value. If value is passed to setjmp as 0, it is converted to 1.


Previous Page | Next Page | Table of Contents | Index