Article View: comp.std.c
Article #5184Re: function returning pointer to itself
From: Jeff Siegal
Date: Wed, 13 Jul 1988 08:26
Date: Wed, 13 Jul 1988 08:26
23 lines
1117 bytes
1117 bytes
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)(); }
Technical Details
Message-ID:
<9667@eddie.MIT.EDU>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!ames!ll-xn!mit-eddie!fenchurch.mit.edu!jbsReferences:
<5485@batcomputer.tn.cornell.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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