Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.std.c Subject: Re: function returning pointer to itself Message-ID: <5149@haddock.ISC.COM> Date: 14 Jul 88 18:14:22 GMT References: <5485@batcomputer.tn.cornell.edu> <11514@steinmetz.ge.com> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 23 In article <11514@steinmetz.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes: >The first [of three solutions] may only be used if all procedures are global. Not true; the same method works with static functions (provided you correctly forward-declare them as static). >... method three: >This is close to what you want, but gives warnings on some compilers. >I would not use it personally for portability reasons. ... >The assumption is that a pointer to a function returning any one thing >looks like a pointer to a function returning some other thing. I can't >think of any reason this wouldn't be true, but I don't trust it. The dpANS guarantees that you can cast function pointers to other function pointer types and back; as long as you use the "right" type to invoke it. I think there was at least one typo in your code fragment, though. Try this: typedef void (*func_t)(void); /* arbitrary function pointer type */ func_t do_init(void), do_state_1(void); func_t (*next_state)(void) = do_init; next_state = (func_t (*)(void))(*next_state)(); Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint