setjmp -- Define Label for Nonlocal goto


SYNOPSIS
#include <setjmp.h>
int setjmp(jmp_buf env);
DESCRIPTION
setjmp
defines a target for a nonlocal goto
. The call to
setjmp
always returns 0. If another routine, called later by the
caller of setjmp
, issues the call longjmp(env, code)
, the
earlier call to setjmp
is resumed. This time, setjmp
returns
the value contained in the code
argument to longjmp
.
RETURN VALUE
A true return from setjmp
always produces a 0. When control
returns from setjmp
because longjmp
was used, the return value
is nonzero.
CAUTION
Variables of storage class auto
and register
, whose values
have been changed between the setjmp
and longjmp
calls, have
indeterminate values on return to setjmp
unless declared volatile.
EXAMPLE
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
jmp_buf env;
void dummy();
main()
{
int ret;
if ((ret = setjmp(env)) != 0) {
fprintf(stderr, "longjmp called with value %dn", ret);
exit(1);
}
dummy();
fprintf(stderr, "longjmp was not called.n");
}
void dummy()
{
puts("Entering dummy routine.");
longjmp(env, 3);
puts("Never reached.");
}
RELATED FUNCTIONS
longjmp
, sigsetjmp
SEE ALSO
Program Control Functions