An alternative approach, arguably with too much magic:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
#define COR_BEGIN(stateVar) switch(stateVar) { case 0:;
#define COR_END(stateVar) }; stateVar = -1;
#define COR_RETURN(stateVar) do { stateVar=__LINE__; return; case __LINE__:;} while (0)
void dofunc(int* pstate)
{
COR_BEGIN(*pstate);
while (computation1)
COR_RETURN(*pstate);
while (computation2)
COR_RETURN(*pstate);
COR_END(*pstate);
}As to debugging, I don't think setjmp/longjmp gets in the way of debuggers at all.