8. Setjmp.h
The header file setjmp is used to control the underlying calls and function jumps.
Macro:
SETJMP ();
Function:
LONGJMP ();
Variable:
typedef JMP_BUF
8.1. Variables and definitions
A variable jmp_buf is an array type that stores setjmp and longjmp information.
8.2. setjmp
Statement:
int setjmp (JMP_BUF environment);
Stores the current running environment environment variables. If you return a value other than 0, it indicates that LONGJMP has reached the location in the source code. Otherwise, the running environment is stored.
8.3. longjmp
Statement:
void longjmp (JMP_BUF environment, int value);
This function causes environment to restore the environment value stored when the call setjmp. This function turns the program back to the setjmp where it was called, as if setjmp returned the value of a value variable. The value of the variable value is not returned to 0. If the transmission is 0, use one instead. The return value is indeterminate if the function that called setjmp has already run terminated.
Instance:
#include <setjmp.h>
#include <stdio.h>
void some_function (JMP_BUF);
int main (void)
{
int value;
Jmp_buf Environment_buffer;
VALUE=SETJMP (environment_buffer);
if (value!=0)
{
printf ("reached", "longjmp with value=%d.\n", value);
Exit (0);
}
printf ("Calling function.\n");
Some_function (environment_buffer);
return 0;
}
void Some_function (Jmp_buf env_buf)
{
longjmp (env_buf,5);
}
The output of the program is:
Calling function.
Reached this is longjmp with value=5.
Original English: http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.8.html
Original Author: Eric Huss
Chinese translator: Liu Yong poechant
Copyright: The original copy of this article is owned by Eric Huss, and the Chinese translation is poechant All rights reserved. Reprint please specify from "Liuda csdn blog": http://blog.csdn.net/poechant