SETJMP(3C) UNIX Programmer's Manual SETJMP(3C) NAME setjmp, longjmp - non-local goto SYNOPSIS #include int setjmp (env) jmp_buf env; longjmp (env, val) jmp_buf env; HP-UX COMPATIBILITY Level: HP-UX/RUN ONLY Origin: System III DESCRIPTION These routines are useful for dealing with errors and inter- rupts encountered in a low-level subroutine of a program. _S_e_t_j_m_p saves its stack environment in _e_n_v for later use by _l_o_n_g_j_m_p. It returns value 0. _L_o_n_g_j_m_p restores the environment saved by the last call of _s_e_t_j_m_p. It then returns in such a way that execution con- tinues as if the call of _s_e_t_j_m_p had just returned the value _v_a_l to the corresponding call to _s_e_t_j_m_p, which must not itself have returned in the interim. _L_o_n_g_j_m_p cannot return the value 0. If _l_o_n_g_j_m_p is invoked with a second argument of 0, it will return 1. All accessible data have values as of the time _l_o_n_g_j_m_p was called. Upon the return from a _s_e_t_j_m_p call caused by a _l_o_n_g_j_m_p, the values of any register variables are undefined. Depending on such values renders code using register variables non- portable. If a _l_o_n_g_j_m_p is executed and the environment in which the _s_e_t_j_m_p was executed no longer exists, errors can occur. The conditions under which the environment of the _s_e_t_j_m_p no longer exists include: exiting the procedure which contains the _s_e_t_j_m_p call, and exiting an inner block with temporary storage (e.g. a block with declarations in C, a _w_i_t_h state- ment in Pascal). This condition may or may not be detect- able. An attempt is made by determining if the stack frame pointer in _e_n_v points to a location not in the currently active stack. If this is the case, _l_o_n_g_j_m_p will return a -1. Otherwise, the _l_o_n_g_j_m_p will occur, and if the environ- ment no longer exists, the contents of the temporary storage of an inner block are unpredictable. This condition may also cause unexpected process termination. If the procedure has been exited the results are unpredictable. Passing _l_o_n_g_j_m_p a pointer to a buffer not created by _s_e_t_j_m_p, or a buffer that has been modified by the user, can cause all the problems listed above, and more. The Pascal language may support a _t_r_y/_r_e_c_o_v_e_r mechanism, which also creates stack marker information. If a _l_o_n_g_j_m_p operation occurs in a scope which is nested inside a try/recover, and the corresponding _s_e_t_j_m_p is not inside the scope of the try/recover, the recover block will not be exe- cuted and the currently active recover block will become the one enclosing the _s_e_t_j_m_p (if there is one). HARDWARE DEPENDENCIES Series 500: Register variables remain defined upon returning from a _s_e_t_j_m_p call caused by a _l_o_n_g_j_m_p. Note that depending on these variables is discouraged for the sake of port- able code. SEE ALSO signal(2).