At 05:54 AM 9/30/99 -0400, W Gerald Hicks wrote:
>
>> doing state machines with switch statements is a big mess.
>
>Still, you'll find a lot of them around.  Do you have a favored
>technique for coding complex state machines?  (I'm a collector :)


yes, state tables. Clean and easy to modify.

>
>One scheme I've been using for quite some time is to use a function
>pointer as a 'state variable', sometimes making a stack of them for
>a more flexible machine.
>
>Sometimes I use a transition matrix for selection of the 'state function'
>but more often the functions themselves perform 'next state' selection.

then your back to switch statements, because you have actions that are used
in multiple states.

event=decode_event(cur_state,pdata);
do_action(cur_state[event][action]);
new_state=cur_state[event][newstate];


Dennis






To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to