setjmp

Provides a way to transfer control from a nested series of function invocations back to a predefined point without returning normally. It does not use a series of return statements. The setjmp function saves the context of the calling function in an environment buffer.

Format

#include  <setjmp.h>

int setjmp  (jmp_buf env);

Argument

env
The environment buffer, which must be an array of integers long enough to hold the register context of the calling function. The type jmp_buf is defined in the <setjmp.h> header file. The contents of the general-purpose registers, including the program counter (PC), are stored in the buffer.

Description

When setjmp is first called, it returns the value 0. If longjmp is then called, naming the same environment as the call to setjmp, control is returned to the setjmp call as if it had returned normally a second time. The return value of setjmp in this second return is the value supplied by you in the longjmp call. To preserve the true value of setjmp, the function calling setjmp must not be called again until the associated longjmp is called.

The setjmp function preserves the hardware general purpose registers, and the longjmp function restores them. After a longjmp, all variables have their values as of the time of the longjmp except for local automatic variables not marked volatile. These variables have indeterminate values.

The setjmp and longjmp functions rely on the OpenVMS condition- handling facility to effect a nonlocal goto with a signal handler. The longjmp function is implemented by generating a DEC C RTL specified signal that allows the OpenVMS condition-handling facility to unwind back to the desired destination.

The DEC C RTL must be in control of signal handling for any DEC C image. For DEC C to be in control of signal handling, you must establish all exception handlers through a call to the VAXC$ESTABLISH function. See Section 4.2.5 and the VAXC$ESTABLISH function in this section for more information.

Restrictions

You cannot invoke the longjmp function from an OpenVMS condition handler. However, you may invoke longjmp from a signal handler that has been established for any signal supported by the DEC C RTL, subject to the following nesting restrictions:

Return Values
See the Description section.   


Previous Page | Next Page | Table of Contents | Index