liveBook · Manning

Setjmp/longjmp

The setjmp/longjmp mechanism is a C nonlocal-control-flow facility that saves an execution context and later restores it to transfer control across function-call boundaries.

How 3 Manning books explain it

Modern C, Third Edition

A long jump is a nonlocal control transfer that can move execution across function-call boundaries.

How it is used
Handles exceptional conditions across nested function calls without returning through each call.
How deep it goes
Works through a recursive parser and states target-validity, macro-placement, and volatile constraints without detailing jump-buffer internals.
Examples
Uses a recursive parser whose output failure triggers `longjmp` and whose outer `switch` handles the resulting condition.
What you can do after
Apply it via C’s `<setjmp.h>` interface to route exceptional nested-call failures to a valid recovery target.

Read how Modern C, Third Edition explains setjmp/longjmp →

Modern C

setjmp is a C library macro that saves an execution context and returns zero initially or a nonzero value when control later returns through longjmp.

How it is used
Handles exceptional conditions detected across nested calls of a recursive parser.
How deep it goes
Works through jump-target setup, return paths, and optimization consequences; defers detailed treatment of asynchronous signals.
Examples
Traces a recursive brace parser that reports unmatched braces, excessive nesting, output failure, or interruption.
What you can do after
Apply it via setjmp.h to route exceptional conditions from nested calls to one handling point.

Read how Modern C explains setjmp/longjmp →

Rust in Action: Systems programming concepts and techniques

longjmp is a non-local control-flow function or compiler intrinsic that restores an execution context previously saved by setjmp.

How it is used
Handles low-level errors, interrupts, or shutdown paths that must escape deeply nested call stacks.
How deep it goes
Explains saved contexts, skipped stack frames, recursive behavior, and LLVM declarations, but stops short of full intrinsic implementation details.
Examples
Uses recursive dive() calls, depth-marker output, a saved jump buffer, signal constants, and a shutdown flag.
What you can do after
Build it from scratch as a non-Windows Rust project that invokes LLVM's setjmp and longjmp facilities through unsafe declarations.

Read how Rust in Action: Systems programming concepts and techniques explains setjmp/longjmp →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.