home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!decwrl!mips!octela!shaun
- From: shaun@octel.com (Ralph Neutrino)
- Subject: Re: Q: returning function pointers
- Message-ID: <1992Jul24.212610.7666@octel.com>
- Organization: Octel Communications Inc., Milpitas Ca.
- References: <GABARA.92Jul20144152@eueh30.tuwien.ac.at> <1992Jul20.195626.12620@cs.tu-berlin.de> <1992Jul20.204737.1279@cs.cornell.edu>
- Date: Fri, 24 Jul 1992 21:26:10 GMT
- Lines: 49
-
- In article <1992Jul20.204737.1279@cs.cornell.edu> ressler@cs.cornell.edu (Gene Ressler) writes:
- >In article <1992Jul20.195626.12620@cs.tu-berlin.de> jutta@opal.cs.tu-berlin.de (Jutta Degener) writes:
- >>gabara@eueh30.tuwien.ac.at (Andrej Gabara) writes:
- >>> I'd like to know whether it is possible that a function can return a function
- >>> of its own type (so that it can return itself).
- >>
- >>It is impossible to describe the type of your function in C.
- >
- >True. Recursive function types can't be written in C, but
- >a recursive struct def and be pressed into service:
-
- [code example deleted (but it surfaces again below)]
-
- If you've been properly conditioned, the line
-
- f("Hello").f("world.").f("This").f("is").f("silly.\n");
-
- can appear to be very close to the desired
-
- f("Hello")("world.")("This")("is")("silly.\n");
-
- by doing
-
- struct fool { struct fool (*fnord)(); } fnord(s)
- char *s;
- {
- struct fool fs; printf("%s ", s); fs.fnord = fnord; return fs;
- }
-
- main()
- {
- fnord("Hello").fnord("world. ").fnord("This").fnord("is").fnord("silly.\n");
- }
-
-
- I'm sure you can use this technique to bag the babes*.
-
- I am only beginning to appreciate the wackiness that pointers to functions can
- lend a program.
-
- @Man
-
- * Or boys, as the case may be.
-
- --
- shaun@octel.com || G is for Jesus
-
- "We will buy Iron Camels from GoMotion
- Unlimited in Santa Clara California."
-