ITPub博客

首页 > > > c语言版本的coroutine

c语言版本的coroutine

作者:友哥 时间:2019-01-16 21:00:00 0 删除 编辑
#include <stdio.h>

int function(void) {
    static int i, state = 0;
    switch (state) {
        case 0: goto LABEL0;
        case 1: goto LABEL1;
    }
    LABEL0: /* start of function */
    for (i = 0; i < 10; i++) {
        state = 1; /* so we will come back to LABEL1 */
        return i;
        LABEL1:; /* resume control straight after the return */
    }
}

int main(){
  printf(":%d\n" , function());
  printf(":%d\n" , function());
  printf(":%d\n" , function());
  printf(":%d\n" , function());
  printf(":%d\n" , function());
  return 0;
}

想过,但是没想到,还真有啊!

原文作者:;如有侵权,请联系管理员删除。

上一篇: 入参检查
请登录后发表评论 登录
全部评论

注册时间:2020-05-20

  • 博文量
    276
  • 访问量
    1000