Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ll-xn!mit-eddie!fenchurch.mit.edu!jbs From: jbs@fenchurch.MIT.EDU (Jeff Siegal) Newsgroups: comp.std.c Subject: Re: function returning pointer to itself Message-ID: <9667@eddie.MIT.EDU> Date: 13 Jul 88 08:26:33 GMT References: <5485@batcomputer.tn.cornell.edu> Sender: uucp@eddie.MIT.EDU Reply-To: jbs@fenchurch.MIT.EDU (Jeff Siegal) Organization: MIT EE/CS Computer Facilities, Cambridge, MA Lines: 22 In article <5485@batcomputer.tn.cornell.edu> olson@tcgould.tn.cornell.edu (olson) writes: >Does the new C standard have a natural way to declare a >function that returns a pointer to itself >???? I'm not sure about a natural way, but the following should suffice: typedef void *(*NextStateFun)(); static void *state1(); static void *state2(); static void *state3(); void *state1() { return (void *)state2; } void *state2() { return (void *)state3; } void *state3() { return NULL; } void * const initial_state = (void *)state1; . . . void *state = initial_state; while (state) { state = (*(NextStateFun)state)(); }