The <setjmp.h> Header File

ANSI-compatible routines for non-local jumps

Functions

longjmp
Performs nonlocal goto.
setjmp
Sets up for nonlocal goto.

Predefined Types

JMP_BUF
A type for capturing a task state.

longjmp

void longjmp (void *j_buf, short ret_val);

Performs nonlocal goto.

A call to longjmp restores the task state captured by the last call to setjmp with the argument j_buf. It then returns in such a way that setjmp appears to have returned with the value ret_val. j_buf is usually a buffer of type JMP_BUF. See setjmp for more info.

Note: longjmp should not be called with a value 0 as ret_val.


setjmp

short setjmp (void *j_buf);

Sets up for nonlocal goto.

setjmp captures the complete task state in j_buf and returns 0. j_buf is usually a buffer of type JMP_BUF. A later call to longjmp with j_buf restores the captured task state and returns in such a way that setjmp appears to have returned with the value val. A task state consists of address registers A2-A7, data registers D2-D7, and the program counter.

setjmp must be called before longjmp. The routine that calls setjmp and sets up j_buf must still be active and cannot have returned before the longjmp is called. If it has returned, the results are unpredictable (and usually results with a crash). setjmp is useful for dealing with errors and exceptions encountered in a low-level subroutine of a program. setjmp returns 0 when it is initially called. If the return is from a call to longjmp, setjmp returns a nonzero value.

Note: The saved task state is not complete enough that setjmp can be used to implement coroutines (i.e. multitasking). Namely, registers A0, A1, D0, D1 and SR are not included into the task state.


JMP_BUF

typedef struct {
unsigned long D2, D3, D4, D5, D6, D7;
unsigned long A2, A3, A4, A5, A6, A7;
unsigned long PC;
} JMP_BUF [1];

A type for capturing a task state.

JMP_BUF is a type designed for capturing a task state needed for the setjmp and longjmp commands.


Return to the main index