Electronic Circuits - Electronic Tutorials - Electronic Hobby Projects - A Complete Electronic Resource Centre

C Language Programming Library Reference Guide

Products

Sitemap

Online
Calculators

Circuits (A-C)

Circuits (D-O)

Circuits (P-Z)

Tutorials


 
Google
 
Web Hobbyprojects.com

setjmp.h - longjmp

Declaration:
void longjmp(jmp_buf environment, int value);
Causes the environment to be restored from a setjmp call where the environment variable had been saved. It causes execution to goto the setjmp location as if setjmp had returned the value of the variable value. The variable value cannot be zero. However, if zero is passed, then 1 is replaced. If the function where setjmp was called has terminated, then the results are undefined.

Example:

#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 output from this program should be:
 
Calling function.
Reached this point from a longjmp with value=5.
Search
Custom Search

<<<  Back to C Language Library Reference Guide

<<<  Back to Electronics Tutorials