setjmp - C setjmp.h

C examples for setjmp.h:setjmp

type

macro

From

<setjmp.h>
<csetjmp>

Description

Save calling environment for long jump

Prototype

int setjmp (jmp_buf env);

Description

fills env with information about the current state of the calling environment

Parameters

Parameter Description
env Object of type jmp_buf where the environment information is stored.

Return Value

This macro may return more than once.

On its direct invocation, it always returns zero.

When longjmp is called, the macro returns the value passed to longjmp as second argument if this is different from zero, or 1 if it is zero.

Demo Code


#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

int main()// ww  w  .  ja va  2  s  . c o  m
{
  jmp_buf env;
  int val;

  val = setjmp (env);
  if (val) {
    fprintf (stderr,"Error %d happened",val);
    exit (val);
  }

  longjmp (env,101);   /* signaling an error */

  return 0;
}

Related Tutorials