Http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.8.html.
Author: Eric Huss
Chinese translator: Liu jinhong poechant
Copyright Disclaimer: the original text in this article is copyrighted by Eric Huss, and the Chinese translation is copyrighted by poechant. Reprinted please indicate from "LIU Da's csdn blog": http://blog.csdn.net/poechant
8. setjmp. h
The header file setjmp is used to control underlying calls and function redirects.
MACRO:
Setjmp ();
Function:
Longjmp ();
Variable:
Typedef jmp_buf
8.1.
Variables and definitions
VariableJmp_bufIs an array type for storageSetjmpAndLongjmpInformation.
8.2. setjmp
Statement:
Int setjmp (jmp_bufEnvironment);
Store the current running environmentEnvironmentVariable. If a non-zero value is returned, it indicatesLongjmpTo the position where the source code is run. Otherwise, the running environment is stored.
8.3. longjmp
Statement:
Void longjmp (jmp_bufEnvironment, IntValue);
This function willEnvironmentResume callSetjmpStoredEnvironmentValue. When this function is used, the program is switched to a previously called one.SetjmpAs ifSetjmpReturnValueThe value of the variable is the same. VariableValueThe value is not returned to 0. If 0 is passed, 1 is used instead. If the function that calls setjmp has been terminated, the return value is uncertain.
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 this point from a 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 program output is:
Calling function.
Reached this point from a longjmp with value = 5.
This series of translations is being updated continuously
(1) assert. HC standard Library Reference Guide series (2) ctype. HC standard Library Reference Guide series (3) errno. HC standard Library Reference Guide series (4) float. HC standard Library Reference Guide series (5) limits. HC standard Library Reference Guide series (6) locale. HC standard Library Reference Guide series (7) math. HC standard Library Reference Guide series (8) setjmp. HC standard Library Reference Guide series translations (9) signal. HC standard Library Reference Guide series translations (10) stdarg. HC standard Library Reference Guide series (11) stddef. HC standard Library Reference Guide series translations (12) stdio. H ()
Copyright Disclaimer: the original text in this article is copyrighted by Eric Huss, and the Chinese translation is copyrighted by poechant. Reprinted please indicate from "LIU Da's csdn blog": http://blog.csdn.net/poechant
-