Site hosted by Angelfire.com: Build your free website today!

Table of Contents Previous Next


1.8 The Standard Headers: <setjmp.h>

The declarations in <setjmp.h> provide a way to avoid the normal function call and return sequence, typically to permit an immediate return from a deeply nested function call.


int setjmp(jmp_buf env);
The macro setjmp saves state information in env for use by longjmp.  A call to setjmp can occur only in certain contexts, basically the test of if, switch, and loops, and only in simple relational expressions.

Returns
The return is zero from a direct call of setjmp, and non-zero from a subsequent call of setjmp.

Example
       if (setjmp(env) == 0)
          /* get here on direct call */
       else
          /* get here by calling longjmp */


int longjmp(jmp_buf env, int val);
longjmp restores the state saved by the most recent call to setjmp, using the information saved in env, and execution resumes as if the setjmp had just executed and returned the non-zero value val.  The function containing the setjmp must not have terminated.  Accessible objects have the values they had at the time longjmp was called; values are not saved by setjmp.


Table of Contents Previous Next

Last modified: Fri Feb 25 13:52:15 2000