Listing 1: The FSM header file
1: typedef short Signal; 2: typedef struct Event Event; 3: typedef struct Fsm Fsm; 4: typedef void (*State)(Fsm *, Event const *); 5: 6: struct Event { /* Event base class */ 7: Signal sig; 8: }; 9: 10: struct Fsm { /* Finite State Machine base class */ 11: State state__; /* the current state */ 12: }; 13: /* "inlined" methods of Fsm class */ 14: #define FsmCtor_(me_, init_) ((me_)->state__ = (State)(init_)) 15: #define FsmInit(me_, e_) (*(me_)->state__)((me_), (e_)) 16: #define FsmDispatch(me_, e_) (*(me_)->state__)((me_), (e_)) 17: #define FsmTran_(me_, targ_) ((me_)->state__ = (State)(targ_))