[comp.lang.c] "recursive" function prototype?

bvs@light.uucp (Bakul Shah) (05/07/88)

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