Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual
Product codes
SW006021-1
Library Functions
2012 Microchip Technology Inc.
DS52053B-page 343
Return Value
Zero if the argument is negative.
LONGJMP
Synopsis
#include <setjmp.h>
void longjmp (jmp_buf buf, int val)
Description
The
longjmp()
function, in conjunction with setjmp(), provides a mechanism for
non-local goto’s. To use this facility, setjmp() should be called with a
jmp_buf
argument in some outer level function. The call from setjmp() will return 0.
To return to this level of execution,
longjmp()
may be called with the same
jmp_buf
argument from an inner level of execution. However, the function that called setjmp()
must still be active when
must still be active when
longjmp()
is called. Breach of this rule will cause errors, due
to the use of a stack containing invalid data. The
val
argument to
longjmp()
will be
the value apparently returned from the setjmp(). This should normally be non-zero,
to distinguish it from the genuine setjmp() call.
to distinguish it from the genuine setjmp() call.
Example
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
jmp_buf jb;
void
inner (void)
{
longjmp(jb, 5);
}
void
main (void)
{
int i;
if(i = setjmp(jb)) {
printf("setjmp returned %d\n" i);
exit(0);
}
printf("setjmp returned 0 - good\n");
printf("calling inner...\n");
inner();
printf("inner returned - bad!\n");
}
See Also
setjmp()
Return Value
The
longjmp()
routine never returns.