The following code just ends up printing "5"
#include <iostream>
#include <setjmp.h>
static jmp_buf buf;
float funcB()
{
setjmp(buf);
return 1.6f;
}
int funcA()
{
longjmp(buf,5);
std::cout<<"b";
return 2;
}
int main()
{
funcB();
std::cout<<funcA();
}
But this doesn't make any sense, as setjmp is returning 5, not either function... Don't worry, I'm not using this code anywhere, I'm just curious!
What you are trying to do is specifically designated as undefined behavior in the documentation:
Since the function that called
setjmp
(i.e.funcB
) has exited before you calllongjmp
infuncA
, the behavior is undefined (it crashes on ideone).