13.12 csetjmp

   

13.12 <csetjmp>

The <csetjmp> header is the C++ version of the C standard <setjmp.h> header.

This chapter presents only the most cursory description of this header because its use is limited in a C++ program. Use exceptions instead of the functions in <csetjmp> .

jmp_buf type Jump buffer

 typedef  . . .  jmp_buf  ; 

The jmp_buf type is an opaque array type that stores information for the setjmp and longjmp functions.

longjmp function Performs nonlocal goto

 void  longjmp  (jmp_buf env, int val); 

The longjmp function bypasses the normal function return and unwinds the call stack to the point where setjmp was called with the same jmp_buf environment. When setjmp returns to its caller, it returns val ; if val is , setjmp returns 1 .

Calling longjmp is similar to throwing an exception that is caught at the point of the setjmp call. One important difference, however, is that if any objects on the stack would have been destroyed by throwing an exception, the program's behavior is undefined if you call longjmp . This is why you should use exceptions instead of longjmp .

setjmp function Establishes nonlocal label

 int  setjmp  (jmp_buf env); 

The setjmp function stores the current execution environment in its argument so that the environment can be restored by a call to longjmp . The first time setjmp is called, it returns . When longjmp is called, setjmp returns the val argument that was passed to longjmp ; that value is guaranteed to be nonzero.

   


C++ in a Nutshell
C++ in a Nutshell
ISBN: 059600298X
EAN: 2147483647
Year: 2005
Pages: 270
Authors: Ray Lischner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net