C Standard Library Reference Guide translation series (8) setjmp. h

Source: Internet
Author: User

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

-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.