
------------------------------------------------------------------------------
4.2 Execute a non-local jump. <Main,Alarm,Comm>
------------------------------------------------------------------------------
[Name]
longjmp
[Syntax]
#include <setjmp.h>
void longjmp( jmp_buf env, int value ) ;
[Arguments]
env Buffer in which contents of stack is saved.
value Return value of "setjmp".
[Return]
------
[Description]
"longjmp" restores environment which has been saved by "setjmp"
before, and jumps to the previous "setjmp" function. This enables
jumping between functions. When "setjmp" is called from "longjmp",
"setjmp" returns "value" which is an one of arguments of "longjmp".
If "value" is zero, "setjmp" returns 1. After re-calling "setjmp",
values of all variables are ones at calling "longjmp". Global
variables whish has been changed by the other functions are not
restored. All register variables are undefined. Usually, "setjmp" is
called in the function which calls a function in which "longjmp" is
called. That is, "setjmp" must be the outer nested function than
"longjmp". When "longjmp" jumps to an inner function, the program
doesn't work correctly.
outer <- -> inner
main()-+-- process1() ---- process2() ---- process3()
│ calls calls calls
│ setjmp() longjmp() longjmp()
│ <---------+ │
│ <-------------------------+
│ ^^^ GOOD
│ │││
│ │││
│ │││ NO GOOD
│ │││
│ ││+----------------------------+
│ │+------------+ │
+-- process4() ---- process5() ---- process6()
calls calls calls
longjmp() longjmp() longjmp()
This function use the library supplied together with the compiler.
For details, see "How to make application program."