- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library function - longjmp()
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 that will produce the following result −
Jump function call Returned from a longjmp() with value = tutorialspoint.com
setjmp_h.htm
Advertisements