tags:

views:

64

answers:

3

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
Thanks for ur response.
priya
+1  A: 

See this simple example on how to implement a finite state machine in C.

the_drow
Thanks for ur response.
priya
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
Thanks for ur response.
priya