C library functions - longjmp ()
C standard library - <setjmp.h>
description
C library functionsvoid longjmp (jmp_buf environment, int value ) to restore a recent call to setjmp ()macro to save the environment by settingjmp_bufparameters before calling setjmp () generates.
statement
Here is the longjmp () function's declaration.
void longjmp(jmp_buf environment, int value)
parameter
- environment - this is a type of jmp_bufobject that contains information about the environment when you call setjmp store.
- value - This is the setjmpexpression to determine value.
return value
This function does not return a value.
Examples
The following example demonstrates the use of longjmp () function.
#include <stdio.h> #include <stdlib.h> #include <setjmp.h> int main() { int val; jmp_buf env_buffer; /* 保存 longjmp 的调用环境 */ val = setjmp( env_buffer ); if( val != 0 ) { printf("从 longjmp() 返回值 = %s\n", val); exit(0); } printf("跳转函数调用\n"); jmpfunction( env_buffer ); return(0); } void jmpfunction(jmp_buf env_buf) { longjmp(env_buf, "w3cschool.cc"); }
Let's compile and run the above program, which will result in the following:
跳转函数调用 从 longjmp() 返回值 = w3cschool.cc