Xref: utzoo comp.lang.c++:1096 comp.lang.c:9998
Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!light!bvs
From: bvs@light.uucp (Bakul Shah)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: "recursive" function prototype?
Message-ID: <1988May6.162213.1633@light.uucp>
Date: 6 May 88 23:22:11 GMT
References: <2549@phoenix.Princeton.EDU> <461@goofy.megatest.UUCP> <7104@bellcore.bellcore.com> <11374@mimsy.UUCP>
Reply-To: bvs@light.UUCP (Bakul Shah)
Organization: Light Systems, Mountain View, CA
Lines: 26


The following is not exactly what was asked for but it is the only way
in C of defining self-type returning functions _without_ using casts.

struct  state {
	struct state (*next)(struct state);
};

Example use:

state_machine(struct state initstate)
{
	struct state state = initstate;

	while (state.next)
		state = state.next(state);
}

The need for some extra syntactic sugar is unfortunate but (to my way of
thinking) preferable to use of ``casts'' or ``void (*)()''s.  Of course,
in practice you rarely want to use a function that returns another
function of the same type.
-- 
Bakul Shah

..!{ucbvax,sun}!amdcad!light!bvs