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.
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.
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.
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
- exceptionAn exception is a runtime signal or value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
- performance optimizationPerformance optimization is the systematic modification of a system or its operation to improve performance measures such as speed, responsiveness, throughput, or resource efficiency.
- referenceA reference is an indirect value, binding, or relationship that identifies or provides access to another object, value, resource, or source.
Related concepts
- jmp_bufuses · jmp_buf is an opaque C library-defined type representing a saved execution environment for setjmp and longjmp.
- macrokind of · 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.
- exceptionaddresses · An exception is a runtime signal or value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
- compiler intrinsickind of · A compiler intrinsic is a compiler-recognized language construct exposing a low-level operation through a special implementation rather than ordinary source code.
- performance optimizationcontrasts with · Performance optimization is the systematic modification of a system or its operation to improve performance measures such as speed, responsiveness, throughput, or resource efficiency.
- stack frameuses · A stack frame is a runtime record that holds the local context and execution state for one active function or method invocation.
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.


