#include <stdio.h>

    
#define BEGIN switch (ctx->state) { \
                        case 0:
    
#define YIELD(val) do { \
                        ctx->state = __LINE__;   \
                        return val;         \
                        case __LINE__:        \
                        ;                   \
                        } while (0)
    
#define END }

typedef struct{
    int state;	
    int i;
}  Ctx;

int foo(Ctx* ctx)
{
    BEGIN;
        while (1) {
        	printf("foo suspending...\n");
        	YIELD(++ctx->i);
        	printf("foo resumed\n");
        }
    END;
    return 0;
} 

int main()
{
    int i=0;

    Ctx t0 = {0,1};
    while (i = foo(&t0)) {
        printf("val: %d\n", i);
        if (i > 10) {
        	printf("enough\n");
        	break; // ideone can't run program indefinitely
        }
    } 

    return 0;
}