2 ms·
In C it is possible to use functions to represent state. To cause a state change, you return a pointer to the function representing the next state. Each state
by nitrogen 15y ago
In C it is possible to use functions to represent state. To cause a state change, you return a pointer to the function representing the next state. Each state function manages transitions away from that state. The main event loop repeatedly calls the current state function with any external input relevant to the system. There is also the giant switch block option, with the current state stored as an enum.
With a little discipline, I think it should be possible to represent state machines in a readable fashion in most popular programming languages.