longjmp(3C)
_________________________________________________________________
longjmp function
Perform a nonlocal jump in the flow of control.
_________________________________________________________________
Calling Sequence
#include <setjmp.h>
void longjmp();
int val;
jmpbuf save;
longjmp(save, val);
where val is a non-zero integer. (If val is 0, longjmp
interprets it as 1.)
Description
The longjmp function performs a nonlocal jump in the flow of
control. To use longjmp, you must first call the setjmp function,
which saves the return address following the setjmp() location.
You can nest your call to the longjmp function as deeply as you
want. It retrieves successive frame pointers until it recovers
the location following the matching setjmp function.
Execution continues as if the call to setjmp had just returned
the value val to the function that called setjmp. That function
must not have returned in the meantime. All accessible register
variables and local data have the same values as they did when
your program called the longjmp function.
The include file setjmp.h defines the longjmp function.
Returns
The longjmp function does not return a value.
Related Functions
See also the setjmp function, described in this chapter, and the
mlongjmp function, described in Chapter 3 of Using Specialized C
Functions.
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
longjmp(3C)
Example
/* Program test for the longjmp() function */
#include <setjmp.h>
void longjmp();
jmp_buf label;
int count = 0;
main() {
printf("\nSetjmp returned %o\n\n", setjmp(label));
if (++count == 3)
exit(0);
recurse(10);
printf("Error\7: recurse should not have returned.\n");
}
recurse(number)
{
printf("Recursing, level %2d\n", number);
if (number > 0)
recurse(number - 1);
else
longjmp(label, 1);
printf("Error\7: longjmp should not have returned.\n");
}
A call to the program test generates the following output:
Setjmp returned 0
Recursing, level 10
Recursing, level 9
Recursing, level 8
Recursing, level 7
Recursing, level 6
Recursing, level 5
Recursing, level 4
Recursing, level 3
Recursing, level 2
Recursing, level 1
Recursing, level 0
Setjmp returned 1
Recursing, level 10
Recursing, level 9
Recursing, level 8
Recursing, level 7
Recursing, level 6
Recursing, level 5
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
longjmp(3C)
Recursing, level 4
Recursing, level 3
Recursing, level 2
Recursing, level 1
Recursing, level 0
Setjmp returned 1
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)