◐ Shell
clean mode source ↗

setjmp — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Déclaré dans l'en-tête

<csetjmp>

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

Enregistre le contexte d'exécution actuel dans un env variable de std::jmp_buf type. Cette variable peut ensuite être utilisé pour restaurer le contexte d'exécution actuel en fonction std::longjmp. Autrement dit, quand un appel à la fonction std::longjmp est faite, l'exécution se poursuit sur le site appel particulier qui a construit la variable std::jmp_buf passé à std::longjmp. Dans ce cas, les rendements setjmp tho valeur passée à 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.

Paramètres

env -

variable pour économiser de l'état d'exécution du programme de .

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.

Retourne la valeur

0 si la macro a été appelée par le code original et le contexte d'exécution a été enregistré env .

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.

Une valeur non nulle si un saut non local a été réalisée juste. La valeur de retour dans le même passé à std::longjmp .

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.

Exemple

#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
    }
}

Résultat :

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

Voir aussi

saute à l'emplacement spécifié

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.


(fonction) [edit]