[Previous]
[Contents]
[Next]

longjmp()

restore the environment saved by setjmp

Synopsis:

#include <setjmp.h>
void longjmp( jmp_buf env, int return_value );

Description:

The longjmp() function restores the environment saved by the most recent call to the setjmp() function with the corresponding env argument.


Note: It's generally a bad idea to use longjmp() to jump out of an interrupt function or a signal handler (unless the signal was generated by the raise() function).

Returns:

After the longjmp() function restores the environment, program execution continues as if the corresponding call to setjmp() had just returned the value specified by return_value. If the value of return_value is 0, the value returned is 1.

Examples:

#include <stdio.h>
#include <setjmp.h>
jmp_buf env;

rtn()
  {
    printf( "about to longjmp\n" );
    longjmp( env, 14 );
  }

void main()
  {
    int ret_val = 293;

    if( 0 == ( ret_val = setjmp( env ) ) ) {
      printf( "after setjmp %d\n", ret_val );
      rtn();
      printf( "back from rtn %d\n", ret_val );
    } else {
      printf( "back from longjmp %d\n", ret_val );
    }
  }

produces the following:

after setjmp 0
about to longjmp
back from longjmp 14

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

setjmp()


[Previous]
[Contents]
[Next]