#include #include struct env { int x; }; struct closure { void (* call)(struct env *); struct env * env; }; void block(struct env * env) { env->x += 1; printf ("block: x is %d\n", env->x); } struct closure foo(int x) { struct env * env = (struct env *)malloc(sizeof(struct env)); env->x = x; printf ("x is %d\n",env->x); struct closure closure; closure.env = env; closure.call = block; return closure; } int main() { struct closure c = foo(5); c.call(c.env); c.call(c.env); }