Provides a means of saving and restoring a processor state.
The setjmp.h functions are typically used for programming error and low-level interrupt handling. The setjmp() function saves the current processor state in its jmp_buf argument. The jmp_buf type holds the processor program counter, stack pointer, and registers. The longjmp() function restores the processor to the state recorded in a variable of type jmp_buf. In other words, longjmp() returns program execution to a point in the program where setjmp() was called. Because the jmp_buf variable can be global, the setjmp() and longjmp() calls do not have to be in the same function body.
Variables assigned to registers through compiler optimization may be corrupted during execution between setjmp() and longjmp() calls. Avoid this situation by declaring affected variables as volatile.