home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / misc / 3583 < prev    next >
Encoding:
Internet Message Format  |  1992-11-10  |  3.4 KB

  1. Path: sparky!uunet!ogicse!decwrl!decwrl!contessa!mwm
  2. From: mwm@contessa.palo-alto.ca.us (Mike Meyer)
  3. Newsgroups: comp.lang.misc
  4. Subject: Re: Pointers
  5. Message-ID: <mwm.2lp7@contessa.palo-alto.ca.us>
  6. Date: 11 Nov 92 06:54:31 GMT
  7. Article-I.D.: contessa.mwm.2lp7
  8. References: <92Nov10.125426est.47525@neat.cs.toronto.edu> <BxIoDv.72J@mentor.cc.purdue.edu> <mwm.2lit@contessa.palo-alto.ca.us> <BxJ39L.LCv@mentor.cc.purdue.edu>
  9. Distribution: world
  10. Organization: Missionaria Phonibalonica
  11. Lines: 62
  12. X-NewsSoftware: Amiga Yarn 3.4, 1992/08/12 15:49:52
  13.  
  14. In <BxJ39L.LCv@mentor.cc.purdue.edu>, hrubin@mentor.cc.purdue.edu (Herman Rubin) wrote:
  15. > In article <mwm.2lit@contessa.palo-alto.ca.us> mwm@contessa.palo-alto.ca.us (Mike Meyer) writes:
  16. > >> You need explicit pointers to functions when the caller does not know
  17. > >> the name of the function being called, but the caller has received a
  18. > >> pointer to the function.
  19. > >No, you don't need *explicit* pointers to functions. It's perfectly
  20. > >reasonable (and I would argue, preferable) to allow function names
  21. > >in argument lists. In C-oid style, this would be:
  22. >         ..............................
  23. > I found this difficult to read, and it does not seem that it handles
  24. > the situation I envision.
  25.  
  26. Herman Rubin finding something difficult to read? That's amazing,
  27. considering what you call "obvious" code. Maybe it's the lack of
  28. extraneous characters that serve little or no useful purpose.
  29.  
  30. > The way that I would want to use pointers
  31. > would be to have fl as the pointer to a fill function, and des as the
  32. > pointer to a descriptor array, of which the first two arguments would
  33. > be pointers to the current element of the buffer and the bounding position,
  34. > and then when it is needed make sure that the current element is correct,
  35. > and issue the call
  36. >     *fl(*des);
  37.  
  38. No problem. That call would look like:
  39.  
  40.     fl(*des) ;
  41.  
  42. > I will consider any suggestions to do this in a better manner, but I
  43. > am not willing to make it any less flexible, nor to put any more burdens
  44. > on the writers of the subprogram, nor of the (usually separately compiled)
  45. > fill functions.
  46.  
  47. You want to make it better? Two things you can do. First, throw away
  48. the silly attachment to pointers per se, and let the compiler handle
  49. the trivia. When you call a function with a function as an argument,
  50. you give it the name of the function as the argument. When you receive
  51. a function as an argument, you declare it - AND USE IT - as a
  52. function. That means you can drop the extra "*" on the call, and on
  53. the reference to the function in the call. No explicit pointers
  54. needed; they are all implicit, and might not be there at all,
  55. depending on how good your compiler is.
  56.  
  57. The net result of this change is to _remove_ a burden from the
  58. programmer of the fill functions. They no longer have to remember
  59. which functions are locally declared functions, and which are things
  60. that are being passed in from outside. They are all functions, and can
  61. be used as such.
  62.  
  63. Second, don't use pointers to code, use closures (which can be done
  64. with the above in place). That's a pair of pointers; one to a piece of
  65. code, and one to the environment the code is supposed to run in. This
  66. allows you to use the same piece of code with local "static" data,
  67. except every "instance" has it's own copy of the static data. If you
  68. think of it as an object in an OO system, you won't be very far wrong.
  69. I'm not going to try and express this in a C-like notation.
  70.  
  71.     <mike
  72.