Could some knowledgable soul tell me if the following setjmp/longjmp
structure will work from a logical standpoint ? The problem is that
bar() needs to suspend processing and return control to foo() but save
it's current spot so that foo() can call bar() and have it pick up
where it left off. I'm fairly certain that bar() can longjmp to foo(),
but I'm uncertain as to whether foo() can then longjmp back to bar().
Thanks in advance for any insight.
Greg.
static jmp_buf l1;
static jmp_buf l2;
void foo(void)
{
if(setjmp(l1) == 0) bar();
-- do stuff --
longjmp(l2);
}
void bar(void)
{
-- do stuff ---
if(setjmp(l2) == 0) longjmp(l1);
-- do more stuff --
}