<< Previous | Next >> | |
|
Description
- Store the PC (program counter), SP (stack pointer) and other information about the current state into
env
. The saved information can be restored by executinglongjmp()
.
NOTE you cannot use setjmp()
to move out of slice statements, costatements, or cofunctions.
- Typical usage:
switch (setjmp(e)) {
case 0: // first time
f(); // try to execute f(), may call longjmp()
break; // if we get here, f() was successful
case 1: // to get here, f() called longjmp()
/* do exception handling */
break;
case 2: // similar to above, but different exception code
...
}
f() {
g()
...
}
g() {
...
longjmp(e,2); // exception code 2, jump to setjmp() statement,
// setjmp() returns 2, so execute
// case 2 in the switch statement
}Parameters
- env
- Information about the current state
Return value
- Returns zero if it is executed. After
longjmp()
is executed, the program counter, stack pointer and etc. are restored to the state whensetjmp()
was executed the first time. However, this timesetjmp()
returns whatever value is specified by thelongjmp()
statement.Library
- SYS.LIB
See also
- longjmp
Dynamic C Functions | << Previous | Next >> | rabbit.com |