User Tools

Site Tools


c_language:state_machines

Brainstorm

Three different approaches:

  • State is kept as a number in a variable. E.g. from a enum. And handled by switch-case
  • State is kept as pointer to struct with function pointers
  • State is kept as a index pointing to a state-transition table

SO question with interesting answers C state machine design.

An article that might contain good stuff State machine shortcuts

A (not really) related pattern that can be used for parsing is the Chain of responsibility pattern.

Ragel – Generate state machines specialized at parsing

PADS – Also for parsing protocols

c_language/state_machines.txt · Last modified: 2022/09/12 00:30 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki