I implemented a simple state machine in Python:
import time
def a():
print \"a()\"
return b
def b():
print \"b()\"
return c
def c():
print
You can get the same effect in C as in Python code,- just declare that functions return (void*)
:
#include "stdio.h"
typedef void* (*myFunc)(void);
void* a(void);
void* b(void);
void* c(void);
void* a(void) {
printf("a()\n");
return b;
}
void* b(void) {
printf("b()\n");
return c;
}
void* c(void) {
printf("c()\n");
return a;
}
void main() {
void* state = a;
while (1) {
state = ((myFunc)state)();
sleep(1);
}
}