home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11575 < prev    next >
Encoding:
Text File  |  1992-07-25  |  1.8 KB  |  60 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!decwrl!mips!octela!shaun
  3. From: shaun@octel.com (Ralph Neutrino)
  4. Subject: Re: Q: returning function pointers
  5. Message-ID: <1992Jul24.212610.7666@octel.com>
  6. Organization: Octel Communications Inc., Milpitas Ca.
  7. References: <GABARA.92Jul20144152@eueh30.tuwien.ac.at> <1992Jul20.195626.12620@cs.tu-berlin.de> <1992Jul20.204737.1279@cs.cornell.edu>
  8. Date: Fri, 24 Jul 1992 21:26:10 GMT
  9. Lines: 49
  10.  
  11. In article <1992Jul20.204737.1279@cs.cornell.edu> ressler@cs.cornell.edu (Gene Ressler) writes:
  12. >In article <1992Jul20.195626.12620@cs.tu-berlin.de> jutta@opal.cs.tu-berlin.de (Jutta Degener) writes:
  13. >>gabara@eueh30.tuwien.ac.at (Andrej Gabara) writes:
  14. >>> I'd like to know whether it is possible that a function can return a function
  15. >>> of its own type (so that it can return itself).
  16. >>
  17. >>It is impossible to describe the type of your function in C.
  18. >
  19. >True.  Recursive function types can't be written in C, but
  20. >a recursive struct def and be pressed into service:
  21.  
  22. [code example deleted (but it surfaces again below)]
  23.  
  24. If you've been properly conditioned, the line 
  25.  
  26.   f("Hello").f("world.").f("This").f("is").f("silly.\n");
  27.  
  28. can appear to be very close to the desired 
  29.  
  30.   f("Hello")("world.")("This")("is")("silly.\n");
  31.  
  32. by doing
  33.  
  34.   struct fool { struct fool (*fnord)(); } fnord(s)
  35.   char *s; 
  36.   { 
  37.     struct fool fs; printf("%s ", s); fs.fnord = fnord; return fs;
  38.   }
  39.   
  40.   main()
  41.   {
  42.     fnord("Hello").fnord("world. ").fnord("This").fnord("is").fnord("silly.\n");
  43.   }
  44.  
  45.  
  46. I'm sure you can use this technique to bag the babes*.
  47.  
  48. I am only beginning to appreciate the wackiness that pointers to functions can
  49. lend a program.
  50.  
  51. @Man
  52.  
  53. * Or boys, as the case may be.
  54.  
  55. -- 
  56. shaun@octel.com  ||  G is for Jesus
  57.  
  58. "We will buy Iron Camels from GoMotion
  59.    Unlimited in Santa Clara California."
  60.