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.
How deep it goes
Explains jump targets, dispatch, lifetime, and portability cautions, but does not enumerate the permitted setjmp expression contexts.
Examples
Uses a recursive brace parser with nesting, unmatched-brace, output-failure, and interruption conditions.
What you can do after
Evaluate and understand when a long jump can route an exceptional condition to a shared handler and what precautions it requires.

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 across nested function calls.
How deep it goes
Explains jump targets, nonreturning control flow, and optimization hazards, contrasting long jumps with goto.
Examples
Uses a recursive brace parser with nesting, output, and interruption error cases.
What you can do after
Apply it via C's <setjmp.h> interface to route exceptional conditions out of nested calls.

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 →

What to know first

Related concepts

Questions about setjmp/longjmp

What is 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.

Which Manning books explain setjmp/longjmp?

Modern C, Third Edition, Modern C and Rust in Action: Systems programming concepts and techniques.

What should I know before learning setjmp/longjmp?

Manning books that teach setjmp/longjmp usually introduce exception, performance optimization and reference first.

What is the difference between setjmp/longjmp and performance optimization?

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. Performance optimization is the systematic modification of a system or its operation to improve performance measures such as speed, responsiveness, throughput, or resource efficiency.

What is setjmp/longjmp a kind of?

Setjmp/longjmp is a kind of macro. A macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.

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.