HI.. I want an example of how to implement FSM using function pointers in C.
A:
An example is too big to write as an answer here.
Here's an existing example, which I found by Googling for state machine c "function pointer"
: Implementing Efficient State Machines
ChrisW
2010-08-19 09:44:49
Thanks for ur response.
priya
2010-08-20 05:28:55
+1
A:
See this simple example on how to implement a finite state machine in C.
the_drow
2010-08-19 09:47:03
A:
I would say initialize a array of pointers to event handlers. So each element of a array is a function pointer to a particular event which is part of an enum.
if foo
is your array of function pointers which is initialized to event then call foo[event]()
when any event occurs.
Try coding for calling a function pointer first, next you can move to array and come back to SO if there are more doubts.
For a start you can read about function pointers here.
Praveen S
2010-08-19 10:56:11