The right-left rule

Ed Korsberg korsberg at abaa.uucp
Wed Jul 18 00:25:50 AEST 1990


In article <1990Jul16.195111.5976 at kfw.COM> will at kfw.com (Will Crowder) writes:
>[150 lines about the right-left rule]

I have a table driven FSM with a state variable (state_variable) which points to 
one of several state tables (see trivial example below).  Given the current 
state (state_variable) and an event, I want to call the appropriate action 
(func_x in tables).

void            (*state1_table[]) () =
{
    func_1                /* EVENT 1 */
    ,func_2               /* EVENT 2 */
    ,func_3               /* EVENT 3 */
    ,func_4               /* EVENT 4 */
};

void            (*state2_table[]) () =
{
    func_1                /* EVENT 1 */
    ,func_2               /* EVENT 2 */
    ,func_7               /* EVENT 3 */
    ,func_6               /* EVENT 4 */
};

void            (*state3_table[]) () =
{
    func_1                /* EVENT 1 */
    ,func_8               /* EVENT 2 */
    ,func_0               /* EVENT 3 */
    ,func_4               /* EVENT 4 */
};


fsm(event)
unsigned int event;			/* occurance of EVENT n */
{
	void	(*action)();
	
	action = state_variable[event]; /* From STATE and EVENT, get action */
	(*action)();			/* perform action */
}

****************************************************************************
Problem is how do you declare a pointer to an array of pointers of functions 
returning void?

I need something like 
	void (*state_variable)[]
but cannot seem to get the syntax correct.  
Any help on this would be appreciated.
---------------------------------------------------------------------------

Ed Korsberg	korsberg at aa.ab.com



More information about the Comp.lang.c mailing list