longjmp


Non-local jump

[Classification]

Standard library

[Syntax]

#include <setjmp.h>

void longjmp(jmp_buf env, int val);

[Description]

This function performs a non-local jump to the place immediately after setjmp using env saved by setjmp. val as a return value for setjmp.

 

[Definition of jmp_buf type in setjmp.h]

typedef int     jmp_buf[14];

[Caution]

When this function is called, only data in the registers reserved by the compiler are saved and restored.

If setjmp is called from within a function in the 22-register mode or common-register mode, data in r20 to r24 are destroyed from within a function in the 32-register mode, and longjmp is then called, the values of r20 to r24 will not be recoverable. In such cases, the values of r20 to r24 must be restored before longjmp is called if they are required.

When -Xep=fix is specified, ep/fix/libsetjmp.lib must be used.

[Example]

#include    <setjmp.h>
#define ERR_XXX1    1
#define ERR_XXX2    2
 
jmp_buf jmp_env;
 
void main(void) {
    for(;;) {
        switch(setjmp(jmp_env)) {
            case    ERR_XXX1:
                /*termination of error XXX1*/
                break;
            case    ERR_XXX2:
                /*termination of error XXX2*/
                break;
            case    0:          /*no non-local jumps*/
            default:
                break;
        }
    }
}
 
void funcXXX(void) {
    longjmp(jmp_env, ERR_XXX1); /*Non-local jumps are performed upon generation of
                                  error XXX1.*/
    longjmp(jmp_env, ERR_XXX2); /*Non-local jumps are performed upon generation of
                                  error XXX2.*/
}