table of contents
setjmp(3avr) | avr-libc | setjmp(3avr) |
NAME¶
setjmp - <setjmp.h>: Non-local goto
SYNOPSIS¶
Functions¶
int setjmp (jmp_buf __jmpb)
void longjmp (jmp_buf __jmpb, int __ret) __ATTR_NORETURN__
Detailed Description¶
While the C language has the dreaded goto statement, it can only be used to jump to a label in the same (local) function. In order to jump directly to another (non-local) function, the C library provides the setjmp() and longjmp() functions. setjmp() and longjmp() are useful for dealing with errors and interrupts encountered in a low-level subroutine of a program.
Note
longjmp() can destroy changes made to global register variables (see How to permanently bind a variable to a register?).
For a very detailed discussion of setjmp()/longjmp(), see Chapter 7 of Advanced Programming in the UNIX Environment, by W. Richard Stevens.
Example:
#include <setjmp.h> jmp_buf env; int main (void) {
if (setjmp (env))
{
... handle error ...
}
while (1)
{
... main processing loop which calls foo() some where ...
} } ... void foo (void) {
... blah, blah, blah ...
if (err)
{
longjmp (env, 1);
} }
Function Documentation¶
void longjmp (jmp_buf __jmpb, int __ret) [extern]¶
Non-local jump to a saved stack context.
#include <setjmp.h>
longjmp() restores the environment saved by the last call of setjmp() with the corresponding __jmpb argument. After longjmp() is completed, program execution continues as if the corresponding call of setjmp() had just returned the value __ret.
Note
Parameters
__ret Value to return to the caller of setjmp().
Returns
int setjmp (jmp_buf __jmpb) [extern]¶
Save stack context for non-local goto.
#include <setjmp.h>
setjmp() saves the stack context/environment in __jmpb for later use by longjmp(). The stack context will be invalidated if the function which called setjmp() returns.
Parameters
Returns
Author¶
Generated automatically by Doxygen for avr-libc from the source code.
Fri Nov 24 2023 23:59:10 | Version 2.0.0 |