title: Is there a typical state machine implementation pattern?
body: <p>We need to implement a simple state machine in <strong>C</strong>.<br>
  Is a standard switch statement the best way to go?<br>
  We have a current state (state) and a trigger for the transition.</p>
  
  <pre><code>
  switch(state)
  {
    case STATE_1:
       state = DoState1(transition);
       break;
    case STATE_2:
       state = DoState2(transition);
       break;
  }
  ...
  DoState2(int transition)
  {
     // Do State Work
     ...
     if(transition == FROM_STATE_2) {
       // New state when doing STATE 2 -> STATE 2
     }
     if(transition == FROM_STATE_1) {
      // New State when moving STATE 1 -> STATE 2
     }
     return new_state;
  }
  </code></pre>
  
  <p>Is there a better way <strong>for simple state machines</strong></p>
  
  <p>EDIT:
    For C++, I think the Boost <a href="http://www.boost.org/doc/libs/1_36_0/libs/statechart/doc/index.html" rel="noreferrer">Statechart</a> library might be the way to go.  However, it does <strong>not</strong> help with C.  Lets concentrate on the C use case.</p>