longjmp [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation
HP C/iX Library Reference Manual
longjmp
Restores an environment previously saved by setjmp().
Syntax
#include <setjmp.h>
void longjmp (jmp_buf env, int val);
Parameters
env Passes information needed to restore a previous
environment. This variable was used in a previous call to
setjmp() to save the environment. The type jmp_buf
(defined in <setjmp.h>) defines an array of unsigned
integers. For this reason, the env argument does not
require an & operator.
val Passes a value to be returned by setjmp(). If a zero is
passed in this argument, it is changed to a value of 1 to
ensure that longjmp() never causes setjmp() to return a
zero value.
Return Values
None. Control is returned to the program at the statement following the
call to setjmp.
Description
The longjmp function restores an environment saved in the env argument by
a previous call to setjmp(). If the env argument is not the result of a
successful call to setjmp(), the operation of longjmp() is undefined and
usually results in the program aborting.
After the call to longjmp() completes, the program executes as if the
call to setjmp() (which stored information into the env argument) has
returned a second time. The result of the second return from setjmp() is
the return of the value of the nonzero val argument supplied to
longjmp().
The calling environment defined in env is restored by longjmp(). This
includes trimming the stack so that all stack frames beyond the frame
marked by env are removed.
The longjmp function cannot add stack frames. This means that if a
sequence of functions is:
A == calls ==> B == calls ==> C
and setjmp() is used in function C to save an environment in a global
env, functions B or A may not contain any longjmp() calls that reference
the env values. Only subordinate functions may issue calls to longjmp().
As a special case, a function may issue a longjmp() call that references
a setjmp() within itself, although this is not usually done.
The longjmp function works correctly in the context of signals and
interrupts and any of their associated functions. However, the effects
of invoking longjmp() from a nested signal handler (that is, a function
invoked as a result of a signal raised while handling another signal) are
undefined.
Control does not return directly from a call to longjmp(), so there are
no return values. Instead, control is returned to setjmp(), and the
value stored in val is used as the return value of setjmp().
NOTE This function is also implemented as the macro _longjmp.
See Also
setjmp(), ANSI C 4.6.2.1, POSIX.1 8.1
MPE/iX 5.0 Documentation