How do I declare...

roman at persci.UUCP roman at persci.UUCP
Thu Aug 22 04:18:56 AEST 1985


Either I'm missing the perfectly obvious or I've found something
that's impossible to declare in C, even though it makes sense.  I'm
trying to implement a simple finite state machine with states
represented by C functions.  Each state function would accept some
input value as an argument and return a pointer to the function
implementing the next state, something like this:

STATE_FUNC (*state)(),   /* the current state         */
           *state_1(),   /* a function for each state */
            ... ,
           *state_n();

   for (;;) {
      state = (*state)(get_input());
   }

But how is STATE_FUNC typedef'ed?  It's a pointer to a function which
returns a pointer to a function which returns a pointer...  Any
suggestions?

Obviously, there are other ways to implement a finite state machine,
and I have already chosen one.  Yet this one is conceptually clean, and
it seems that there must be some way to do it; plus, this could turn
out to be a more interesting discussion than i++ vs. i = i + 1...

-- 
Bill Roman	{ihnp4,decvax,allegra,...}!uw-beaver!tikal!persci!roman

Summation, Inc, (formerly Personal Scientific Corporation)
18702 142nd Ave NE
Woodinville, WA 98072
(206) 486-0991



More information about the Comp.lang.c mailing list