#include <setjmp.h>
|
int
setjmp (jmp_buf env); |
void
longjmp (jmp_buf env, int val); |
int
_setjmp (jmp_buf env); |
void
_longjmp (jmp_buf env, int val); |
The corresponding longjmp functions restore the environment saved by their most recent respective invocations of the setjmp function. They then return so that program execution continues as if the corresponding invocation of the setjmp call had just returned the value specified by val, instead of 0.
The longjmp routines may not be called after the routine which called the setjmp routines returns.
All accessible objects have values as of the time longjmp routine was called, except that the values of objects of automatic storage invocation duration that do not have the volatile type and have been changed between the setjmp invocation and longjmp call are indeterminate.
The setjmp / longjmp pairs save and restore the signal mask while _setjmp / _longjmp pairs save and restore only the register set and the stack.
#include <setjmp.h> #include <stdio.h> #include <stdlib.h> static void f1( int, int, int ); static void f2( void ); static jmp_buf jmpbuffer; int main() { int count; register int val; volatile int sum; count = 2; val = 3; sum = 4; if ( setjmp( jmpbuffer ) != 0 ) { printf("in main: count = %d, val = %d, sum = %d\n", count, val, sum ); exit(0); } f1(97, 98, 99 ); return 0; } static void f1 (int i, int j, int k ) { printf("in f1: count = %d, val = %d, sum = %d\n", i, j , k ); f2(); } static void f2( void ) { longjmp( jmpbuffer, 1 ); }
Output
in f1: count = 97, val = 98, sum = 99 in main: count = 2, val = 3, sum = 4
© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user. |