Setjmp.h - Member Functions

Member Functions

int setjmp(jmp_buf env) Sets up the local jmp_buf buffer and initializes it for the jump. This routine saves the program's calling environment in the environment buffer specified by the env argument for later use by longjmp. If the return is from a direct invocation, setjmp returns 0. If the return is from a call to longjmp, setjmp returns a nonzero value.
void longjmp(jmp_buf env, int value) Restores the context of the environment buffer env that was saved by invocation of the setjmp routine in the same invocation of the program. Invoking longjmp from a nested signal handler is undefined. The value specified by value is passed from longjmp to setjmp. After longjmp is completed, program execution continues as if the corresponding invocation of setjmp had just returned. If the value passed to longjmp is 0, setjmp will behave as if it had returned 1; otherwise, it will behave as if it had returned value.

setjmp saves the current environment (i.e., the program state) at some point of program execution, into a platform-specific data structure (jmp_buf) which can be used, at some later point of program execution, by longjmp to restore the program state to that which was saved by setjmp into jmp_buf. This process can be imagined to be a "jump" back to the point of program execution where setjmp saved the environment. The (apparent) return value from setjmp indicates whether control reached that point normally or from a call to longjmp. This leads to a common idiom: if( setjmp(x) ){/* handle longjmp(x) */}.

POSIX.1 does not specify whether setjmp and longjmp save or restore the current set of blocked signals — if a program employs signal handling it should use POSIX's sigsetjmp/siglongjmp.

Read more about this topic:  Setjmp.h

Famous quotes containing the words member and/or functions:

    When I reach the shades at last it will no doubt astonish Satan to discover, on thumbing my dossier, that I was a member of the Y.M.C.A.
    —H.L. (Henry Lewis)

    The mind is a finer body, and resumes its functions of feeding, digesting, absorbing, excluding, and generating, in a new and ethereal element. Here, in the brain, is all the process of alimentation repeated, in the acquiring, comparing, digesting, and assimilating of experience. Here again is the mystery of generation repeated.
    Ralph Waldo Emerson (1803–1882)