]> Pileus Git - ~andy/sfvlug/blob - c/src/sm.c
Add C notes.
[~andy/sfvlug] / c / src / sm.c
1 #include <stdio.h>
2
3 int (*state)(typeof(state));
4
5 int sm_first(state_t *state);
6 int sm_second(state_t *state);
7 int sm_third(state_t *state);
8 int sm_done(state_t *state);
9
10 int sm_first(state_t *state)
11 {
12         printf("first\n");
13         *state = &sm_second;
14         return 1;
15 }
16
17 int sm_second(state_t *state)
18 {
19         *state = &sm_third;
20         printf("second\n");
21         return 1;
22 }
23
24 int sm_third(state_t *state)
25 {
26         *state = &sm_done;
27         printf("third\n");
28         return 1;
29 }
30
31 int sm_done(state_t *state)
32 {
33         printf("done\n");
34         return 0;
35 }
36
37 int main()
38 {
39         state_t state = sm_first;
40         while (state(&state));
41         return 0;
42 }