<< 19/89 >>
First Last

PuTTY's coroutine

 #define crBegin static int state=0; switch(state) { case 0:
 #define crReturn(i,x) do { state=i; return x; case i:; } while (0)
 #define crFinish }
 int function(void) {
     static int i;
     crBegin;
     for (i = 0; i < 10; i++)
         crReturn(1, i);
     crFinish;
 }

=>

 int function(void) {
     static int i;
     static int state=0; switch(state) { case 0:;
     for (i = 0; i < 10; i++)
         do { state=1; return i; case 1:; } while (0);
     };
 }

http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

http://d.hatena.ne.jp/shinichiro_h/20050628#1119942495