#include <setjmp.h> int setjmp(jmp_buf env);
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
.
setjmp
always produces a 0. When control
returns from setjmp
because longjmp
was used, the return value
is nonzero.
auto
and register
, whose values
have been changed between the setjmp
and longjmp
calls, have
indeterminate values on return to setjmp
unless declared volatile.
#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."); }
longjmp
, sigsetjmp
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.