C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
longjmp, setjmp
 Summary Example                         Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
     The setjmp function saves a stack environment that can be
     subsequently restored using longjmp. Used together, setjmp and
     longjmp provide a way to execute a nonlocal goto. They are
     typically used to pass execution control to error-handling or
     recovery code in a previously called routine, without using the
     normal calling or return conventions.
 
     A call to setjmp causes the current stack environment to be saved
     in <env>. A subsequent call to longjmp restores the saved
     environment and returns control to the point immediately following
     the corresponding setjmp call. Execution resumes as if <value> had
     just been returned by the setjmp call.
 
     The values of all variables (except register variables) accessible
     to the routine receiving control contain the values they had when
     longjmp was called. The values of register variables are
     unpredictable.
 
     The longjmp function must be called before the function that
     called setjmp returns. If longjmp is called after the function
     calling setjmp returns, unpredictable program behavior results.
 
     The return value of setjmp, which is longjmp's <value> parameter,
     must be nonzero. If <value> is passed as 0, the value 1 is
     substituted in the actual return.
 
     Observe the following restrictions when using longjmp or setjmp:
 
        ■ Do not assume that the values of the register variables
          will remain the same. The values of the register variables
          in the routine calling setjmp may not be restored to the
          proper values after longjmp is executed. Do not use longjmp
          with the global error allocation (/Oe) option to the CL
          driver.
 
        ■ Do not use longjmp to transfer control from within one
          overlay to within another. The overlay manager keeps the
          overlay in memory after a call to longjmp.
 
        ■ Do not use longjmp to transfer control out of an
          interrupt-handling routine unless the interrupt is caused
          by a floating-point exception. In this case, a program may
          return from an interrupt handler via longjmp if it first
          reinitializes the floating-point math package by calling
          _fpreset.
 
        ■ Neither setjmp nor longjmp is compatible with C++.
 
     Return Value
 
     The setjmp function returns 0 after saving the stack environment.
     If setjmp returns as a result of a longjmp call, it returns the
     value argument of longjmp. If the value argument of longjmp is 0,
     setjmp returns 1. There is no error return.
                                    -♦-