#include <lcjmp.h> void onjmp(jmp_buf env, int code, target);
onjmp
defines the target
label as a point to which control
should be transferred by a call to longjmp
. The longjmp
call
specifies the same env
value as onjmp
. The integer value
specified by the longjmp
call is stored in the code
integer.
onjmp
sets the code
variable to 0 on completion. Because the
occurrence of a longjmp
assigns onjmp
a value other than 0, the value of
code
can be tested elsewhere to determine whether a jump has taken place.
onjmp
has no return value.
auto
and register
, whose values are
changed between the onjmp
and longjmp
calls, have indeterminate
values after the branch to target
unless declared volatile
.
onjmp
is implemented as a macro and should not be used in any
position where a value is required.
onjmp
is not a Standard construct; however, the macro that
implements it is portable to any system that implements setjmp
.
onjmp
is implemented as
#define onjmp(e, c, t) if (c = setjmp(e)) goto tSee
setjmp
for further implementation information.
#include <stdio.h> #include <lcjmp.h> #include <stdlib.h> jmp_buf env; void dummy(); main() { int errcode; /* Allow restart via longjmp. */ onjmp(env, errcode,cleanup); dummy(); puts("No error occurred in dummy routine."); return; cleanup: printf("Beginning cleanup for error number %dn", errcode); } void dummy() { puts("Entering dummy routine."); longjmp(env, 3); puts("Never reached."); }
longjmp
, setjmp
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.