Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site persci.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!tikal!cholula!persci!roman
From: roman@persci.UUCP
Newsgroups: net.lang.c
Subject: How do I declare...
Message-ID: <368@persci.UUCP>
Date: Wed, 21-Aug-85 14:18:56 EDT
Article-I.D.: persci.368
Posted: Wed Aug 21 14:18:56 1985
Date-Received: Sat, 24-Aug-85 17:25:01 EDT
Organization: Personal Scientific Corporation, Woodinville, WA, USA, Earth...
Lines: 32

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