C library function - longjmp()
Advertisements
Description
The C library function void longjmp(jmp_buf environment, int value) restores the environment saved by the most recent call to setjmp() macro in the same invocation of the program with the corresponding jmp_buf argument.
Declaration
Following is the declaration for longjmp() function.
void longjmp(jmp_buf environment, int value)
Parameters
environment -- This is the object of type jmp_buf containing information to restore the environment at the setjmp's calling point.
value -- This is the value to which the setjmp expression evaluates.
Return Value
This function does not return any value.
Example
The following example shows the usage of longjmp() function.
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
int main()
{
int val;
jmp_buf env_buffer;
/* save calling environment for longjmp */
val = setjmp( env_buffer );
if( val != 0 )
{
printf("Returned from a longjmp() with value = %s\n", val);
exit(0);
}
printf("Jump function call\n");
jmpfunction( env_buffer );
return(0);
}
void jmpfunction(jmp_buf env_buf)
{
longjmp(env_buf, "tutorialspoint.com");
}
Let us compile and run the above program, this will produce the following result:
Jump function call Returned from a longjmp() with value = tutorialspoint.com