-

Changes

Jump to: navigation, search

Functions HI-TECH C LONGJMP

1,598 bytes added, 22:20, 31 July 2017
Created page with "<strong>LONGJMP</strong> ==SYNOPSIS== #include <setjmp.h> void longjmp(jmp_buf buf, int val) ==DESCRIPTION== <strong>Longjmp</strong>(), in conjunction with <str..."
<strong>LONGJMP</strong>
==SYNOPSIS==

#include <setjmp.h>

void longjmp(jmp_buf buf, int val)


==DESCRIPTION==
<strong>Longjmp</strong>(), in conjunction with <strong>setjmp</strong>(), provides a
mechanism for non-local gotos. To use this facility,
<strong>setjmp</strong>() should be called with a jmp_buf argument in
some outer level function. The call from <strong>setjmp</strong>() will
return 0. To return to this level of execution,
<strong>lonjmp</strong>() may be called with the same jmp_buf argument
from an inner level of execution. Note however that the
function which called <strong>setjmp</strong>() must still be active
when <strong>longjmp</strong>() is called. Breach of this rule will
cause disaster, due to the use of a stack containing
invalid data. The val argument to <strong>longjmp</strong>() will be the
value apparently returned from the <strong>setjmp</strong>(). This
should normally be non-zero, to distinguish it from the
genuine <strong>setjmp</strong>() call. For example:

#include <setjmp.h>

static jmp_buf jb_err;

main()
{
if(setjmp(jb_err)) {
printf("An error occured0);
exit(1);
}
a_func();
}

a_func()
{
if(do_whatever() != 0)
longjmp(jb_err, 1);
if(do_something_else() != 0)
longjmp(jb_err, 2);
}


The calls to <strong>longjmp</strong>() above will never return; rather
the call to <strong>setjmp</strong>() will appear to return, but with a
return value equal to the argument supplied to
<strong>longjmp</strong>().

==SEE ALSO==

setjmp

Navigation menu