
setjmp/longjmp
7-45
Run-Time-Support Functions
Nonlocal Jumps
setjmp/longjmp
Syntax
#include <setjmp.h>
int
setjmp
(jmp_buf env);
void
longjmp
(jmp_buf env, int returnval);
Defined in
setjmp.asm in rts.src
Description
The setjmp.h header defines a type and a macro and declares a function for
bypassing the normal function call and return discipline:
-
The jmp_buf type is an array type suitable for holding the information
needed to restore a calling environment.
-
The setjmp macro saves its calling environment in the jmp_buf argument
for later use by the longjmp function.
If the return is from a direct invocation, the setjmp macro returns the value
0. If the return is from a call to the longjmp function, the setjmp macro re-
turns a nonzero value.
-
The longjmp function restores the environment that was saved in the
jmp_buf argument by the most recent invocation of the setjmp macro. If
the setjmp macro was not invoked, or if it terminated execution irregularly,
the behavior of longjmp is undefined.
After longjmp is completed, the program execution continues as if the cor-
responding invocation of setjmp had just returned returnval. The longjmp
function does not cause setjmp to return a value of 0 even if returnval is 0. If
returnval is 0, the setjmp macro returns the value 1.
Example
These functions are typically used to effect an immediate return from a deeply
nested function call:
#include <setjmp.h>
jmp_buf env;
main()
{
int errcode;
if ((errcode = setjmp(env)) == 0)
nest1();
else
switch (errcode)
. . .
}
. . .
nest42()
{
if (input() == ERRCODE42)
/* return to setjmp call in main */
longjmp (env, ERRCODE42);
. . .
}
Содержание TMS320C2x
Страница 8: ...viii...
Страница 69: ...2 47 C Compiler Description...
Страница 159: ...6 36...
Страница 226: ...8 6...
Страница 250: ...Index Index 14 Z z shell option 2 2 2 4 2 14 overriding with c option 4 5 overriding with n option 2 13...