Rod Pemberton writes:
> FYI, others have pointed out Simon Tatham's "Coroutines in C":
> http://www.chiark.greenend.org.uk/~s...oroutines.html
Cool. Why didn't anyone tell me about that __LINE__ trick before?

I wouldn't call them coroutines though. Too limited.
Personally I don't see anything ugly about it, BTW. Hiding ugly stuff
is one of the things macros are _for_. Except the crFinish macro, but
that one is not necessary:
#define AutoSwitch(state) /* state=integer state variable */\
switch (state) case 0:
#define AScontrol(state, stmt) /* stmt=return/break/continue/goto */\
if (1) { (state) = __LINE__; stmt; case __LINE__:; } else (void)(0)
Now it's just a normal switch in that break/continue/etc work as
normally - it's just that the case statements look nicer this way.
int foo(void)
{
static int state, cur;
AutoSwitch(state)
for (cur = 1; cur < 10; cur++)
AScontrol(state, return cur*cur);
return 0;
}
--
Hallvard