< cpp‎ | utility‎ | program
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
Relational operators (deprecated in C++20)
Integer comparison functions
Swap and type operations
Common vocabulary types
Elementary string conversions
Program support utilities
Program termination
Unreachable control flow
Communicating with the environment
Signal types
Non-local jumps
Defined in header <csetjmp>
typedef /* unspecified */ jmp_buf;

The std::jmp_buf type is an array type suitable for storing information to restore a calling environment. The stored information is sufficient to restore execution at the correct block of the program and invocation of that block. The state of floating-point status flags, or open files, or any other data is not stored in an object of type std::jmp_buf.

[edit] Example

#include <csetjmp>
#include <iostream>
std::jmp_buf my_jump_buffer;
[[noreturn]] void foo(int status) 
    std::cout << "foo(" << status << ") called\n";
    std::longjmp(my_jump_buffer, status + 1); // setjmp() will return status + 1
int main()
    volatile int count = 0; // modified locals in setjmp scope must be volatile
    if (setjmp(my_jump_buffer) != 5) // equality against constant expression in an if
        count += 1; // Increment of a volatile variable is deprecated since C++20 (P1152)
        foo(count); // This will cause setjmp() to exit


foo(1) called
foo(2) called
foo(3) called
foo(4) called

[edit] See also

saves the context
(function macro) [edit]
jumps to specified location
(function) [edit]
C documentation for jmp_buf