#include <setjmp.h>void longjmp(jmp_buf envbuf, int status);

The longjmp( ) function causes program execution to resume at the point of the last call to setjmp( ). Thus, longjmp( ) and setjmp( ) provide a means of jumping between functions. Notice that the header <setjmp.h> is required. For C++, use the header <csetjmp>.

The longjmp( ) function operates by resetting the stack to the state as described in envbuf, which must have been set by a prior call to setjmp( ). This causes program execution to resume at the statement following the setjmp( ) invocation. That is, the computer is “tricked” into thinking that
it never left the function that called setjmp( ). (As a somewhat graphic explanation, the longjmp( ) function “warps” across time and (memory) space to a previous point in your program without having to perform the normal function return process.)

The buffer evnbuf is of type jmp_buf, which is defined in the header <setjmp.h>. Again, the buffer must have been set through a call to setjmp( ) prior to calling longjmp( ).

The value of status becomes the return value of setjmp( ) and is used to determine where the long jump came from. The only value that is not allowed is zero. Zero is returned by setjmp( ) when it is actually called directly by your program, not indirectly through the execution of longjmp( ).

By far the most common use of longjmp( ) is to return from a deeply nested set of routines when an error occurs.

A related function is setjmp( ).

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

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