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

  1. Path: sparky!uunet!gumby!yale!yale.edu!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.misc
  4. Subject: Re: Pointers
  5. Date: 12 Nov 1992 21:47:10 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 40
  8. Message-ID: <1dujcuINNru4@early-bird.think.com>
  9. References: <BxJzzv.4H7@mentor.cc.purdue.edu> <721539019@sheol.UUCP>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12.  
  13. I think this whole thread is incredibly silly.
  14.  
  15. C's function pointers are almost exactly like the procedure variables that
  16. many other languages have.  As in many other aspects, C has overloaded an
  17. available syntax and used it for some other meaning.  Thus, in C, a
  18. function declaration where the name is preceded by a "*" indicates that
  19. it's a variable that can be assigned dynamically rather than a name that
  20. should be linked.  This is analogous to PL/I's requirement that a procedure
  21. variable declaration have the keyword "variable" in it.
  22.  
  23. Outside the declaration, you don't even have to think of it as a pointer.
  24. All uses of function pointers act just like they do in languages with
  25. procedure variables: assignments reassign the variable, while using it in a
  26. function call syntax causes the referenced function to be called.
  27.  
  28. C function pointers aren't like any other pointers in the language.  You
  29. can't do pointer arithmetic on them.  You're not allowed to indirect
  30. through one except when it's in a function call syntax, and in the latter
  31. case the indirection isn't required.  You can't cast between them and
  32. non-function pointers.
  33.  
  34. One difference between C and most of the other languages with procedure
  35. variables is that C doesn't have nested procedures.  In the other
  36. languages, a procedure variable generally includes both a code pointer and
  37. an environment (in the traditional languages, which don't allow nested
  38. procedures to be returned, this is usually a stack frame pointer).  C
  39. doesn't require environments to be associated with functions because
  40. they're all defined in the global environment, so the C designers could
  41. simply implement procedure variables as pointers to the actual code, and
  42. they specified the declaration syntax accordingly.  But when you look at
  43. C++ and its member function pointers, you see that these are more like the
  44. traditional procedure variables (the environment in this case is the "self"
  45. object); however, they've kept C's function "pointer" syntax for declaring
  46. them.
  47. -- 
  48. Barry Margolin
  49. System Manager, Thinking Machines Corp.
  50.  
  51. barmar@think.com          {uunet,harvard}!think!barmar
  52.