]> Pileus Git - ~andy/sfvlug/blobdiff - c/src/sm.c
Add C notes.
[~andy/sfvlug] / c / src / sm.c
diff --git a/c/src/sm.c b/c/src/sm.c
new file mode 100644 (file)
index 0000000..c17ea1d
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdio.h>
+
+int (*state)(typeof(state));
+
+int sm_first(state_t *state);
+int sm_second(state_t *state);
+int sm_third(state_t *state);
+int sm_done(state_t *state);
+
+int sm_first(state_t *state)
+{
+       printf("first\n");
+       *state = &sm_second;
+       return 1;
+}
+
+int sm_second(state_t *state)
+{
+       *state = &sm_third;
+       printf("second\n");
+       return 1;
+}
+
+int sm_third(state_t *state)
+{
+       *state = &sm_done;
+       printf("third\n");
+       return 1;
+}
+
+int sm_done(state_t *state)
+{
+       printf("done\n");
+       return 0;
+}
+
+int main()
+{
+       state_t state = sm_first;
+       while (state(&state));
+       return 0;
+}