#include
#include
main ()
{
jmp_buf env;
int i;
i = setjmp (env);
printf ("i =% dn", i);
if (i! = 0) exit (0);
longjmp (env, 2);
printf ("Is it printed now?");
}
Compiling and running the above C program will result:
i = 0
i = 2
Only one function is defined in setjmp.h:
Function longjmp void (jmp_buf environment, int value): This function restores the environment (environment) stored by the closest call to the setjmp () macro in the same function call of the program with the corresponding parameter jmp_buf.
Declare the function longjmp () in C
Below is the declaration for longjmp () function in C:
void longjmp (jmp_buf environment, int value)
Parameters:
environment - This is an object of type jmp_buf that contains information to store the environment at the call point of setjmp.
value - This is the value for the setjmp expression to estimate.
Return value:
This function does not return any values.
For example:
The following program C illustrates the usage of the longjmp () function in C:
#include
#include
#include
main ()
{
jmp_buf env;
int i;
i = setjmp (env);
printf ("i =% dn", i);
if (i! = 0) exit (0);
longjmp (env, 2);
printf ("Is it printed now?");
}
Compiling and running the above C program will result:
i = 0
i = 2
According to Tutorialspoint
Last lesson: math.h in C
Next post: signal.h in C