Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site watcgl.UUCP
Path: utzoo!watmath!watnot!watcgl!kdmoen
From: kdmoen@watcgl.UUCP (Doug Moen)
Newsgroups: net.lang.c
Subject: Re: How do I declare... (recursive typedefs)
Message-ID: <2407@watcgl.UUCP>
Date: Sat, 24-Aug-85 15:42:50 EDT
Article-I.D.: watcgl.2407
Posted: Sat Aug 24 15:42:50 1985
Date-Received: Sun, 25-Aug-85 03:17:53 EDT
References: <368@persci.UUCP>
Reply-To: kdmoen@watcgl.UUCP (Doug Moen)
Organization: U of Waterloo, Ontario
Lines: 38
Summary: You can't do recursive typedefs

In article <368@persci.UUCP> roman@persci.UUCP writes:
>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?

You aren't missing the perfectly obvious.
Yes, it is impossible to declare in C, even though it makes sense.

What you want is a recursive typedef:
	typedef STATE_FUNC (*STATE_FUNC)();
except that this isn't allowed.

What you will have to do instead is a kludge:
	typedef char* (*STATE_FUNC)();

	for (;;) {
		/* Note the cast: */
		state = (STATE_FUNC) (*state)(get_input());
	}
-- 
Doug Moen (watmath!watcgl!kdmoen)
University of Waterloo Computer Graphics Lab