◐ Shell
clean mode source ↗

setjmp – cppreference.com

Aus cppreference.com

<metanoindex/>

<tbody> </tbody>

definiert in Header

<csetjmp>

#define setjmp(env) /* implementation-defined */

Speichert die aktuelle Ausführungskontext in eine Variable env vom Typ std::jmp_buf. Diese Variable kann später verwendet, um die aktuelle Ausführung Kontext std::longjmp Funktion wiederherzustellen. Das heißt, wenn ein Anruf an std::longjmp Funktion gemacht wird, geht die Ausführung zum bestimmten Anruf Website, die die variable std::jmp_buf übergebenen std::longjmp konstruiert. In diesem Fall setjmp kehrt tho übergebenen Wert std::longjmp .

Original:

Saves the current execution context into a variable env of type std::jmp_buf. This variable can later be used to restore the current execution context by std::longjmp function. That is, when a call to std::longjmp function is made, the execution continues at the particular call site that constructed the std::jmp_buf variable passed to std::longjmp. In that case setjmp returns tho value passed to std::longjmp.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parameter

env -

Variable, um den Ausführungszustand des Programms zu retten .

Original:

variable to save the execution state of the program to.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Rückgabewert

0 wenn das Makro durch den ursprünglichen Code aufgerufen wurde und die Ausführung Kontext wurde env gespeichert .

Original:

0 if the macro was called by the original code and the execution context was saved to env.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Nicht-Null-Wert, wenn ein Sprung nicht lokalen gerade ausgeführt wurde. Der Rückgabewert der gleiche wie für std::longjmp übergeben .

Original:

Non-zero value if a non-local jump was just performed. The return value in the same as passed to std::longjmp.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Beispiel

#include <iostream>
#include <csetjmp>

std::jmp_buf jump_buffer;

[[noreturn]] void a(int count) 
{
    std::cout << "a(" << count << ") called\n";
    std::longjmp(jump_buffer, count+1);  // setjump() will return count+1
}

int main()
{
    int count = setjmp(jump_buffer);
    if (count != 9) {
        a(count);  // This will cause setjmp() to exit
    }
}

Output:

a(0) called
a(1) called
a(2) called
a(3) called
a(4) called
a(5) called
a(6) called
a(7) called
a(8) called

Siehe auch

springt zum angegebenen Ort

Original:

jumps to specified location

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(Funktion) [edit]