C Standard Library Reference Guide (8) setjmp.h

Source: Internet
Author: User
Tags include variables printf

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

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.