fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define DECLARE() int state = 0
  4.  
  5. #define BEGIN switch (state) { \
  6.   case 0:
  7.  
  8. #define YIELD(val) do { \
  9.   state = __LINE__; \
  10.   return val; \
  11.   case __LINE__: \
  12.   ; \
  13.   } while (0)
  14.  
  15. #define END }
  16.  
  17. int next()
  18. {
  19. static DECLARE();
  20. static int i=1;
  21. BEGIN;
  22. YIELD(++i);
  23. YIELD(++i);
  24. END;
  25. return 0;
  26. }
  27. int main()
  28. {
  29. int num;
  30. while (num = next()) {
  31. printf("%d\n", num);
  32. }
  33. printf("done\n");
  34. return 0;
  35. }
Success #stdin #stdout 0s 5648KB
stdin
Standard input is empty
stdout
2
3
done