C Standard Libraries C++

setjmp()

Declaration

int setjmp(jmp_buf qEnvironment);

Description

This function puts the current stack environment into the passed in argument and returns 0. If setjmp() is called after longjmp(), then setjmp() returns the value that was passed in to longjmp() unless a zero was passed in, in which case setjmp returns 1.

Example

#include <iostream>
#include <csetjmp>

int main() {
    using namespace std;

    jmp_buf qEnv;
    // Get the stack environment in qEnv
    int iRet = setjmp(qEnv);
    // Cast to a _JUMP_BUFFER for easier access - Microsoft specific
    _JUMP_BUFFER* qpStackEnv = (_JUMP_BUFFER*)(&qEnv);
    cout << "Return value   = " << iRet << endl;
    cout << "Cookie     = " << qpStackEnv->Cookie << endl;
    cout << "Ebp        = " << qpStackEnv->Ebp << endl;
    cout << "Ebx        = " << qpStackEnv->Ebx << endl;
    cout << "Edi        = " << qpStackEnv->Edi << endl;
    cout << "Eip        = " << qpStackEnv->Eip << endl;
    cout << "Esi        = " << qpStackEnv->Esi << endl;
    cout << "Esp        = " << qpStackEnv->Esp << endl;
    cout << "Registration   = " << qpStackEnv->Registration << endl;
    cout << "TryLevel   = " << qpStackEnv->TryLevel << endl;
    for (unsigned int uiIndex = 0; uiIndex < 6; ++uiIndex) {
        cout << "UnwindData[" << uiIndex << "]  = "
            << qpStackEnv->UnwindData[uiIndex] << endl;
    }
    cout << "UnwindFunc = " << qpStackEnv->UnwindFunc << endl;

    return 0;
}

Output

setjmp() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.