home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / misc / 3502 < prev    next >
Encoding:
Text File  |  1992-11-06  |  4.3 KB  |  87 lines

  1. Newsgroups: comp.lang.misc
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!cs.utexas.edu!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  3. From: jlg@cochiti.lanl.gov (J. Giles)
  4. Subject: Re: Pointers
  5. Message-ID: <1992Nov5.184831.16328@newshost.lanl.gov>
  6. Sender: news@newshost.lanl.gov
  7. Organization: Los Alamos National Laboratory
  8. References: <1992Nov4.093545.15950@rdg.dec.com> <Bx7oAz.7Lp@mentor.cc.purdue.edu> <1992Nov5.014143.15635@newshost.lanl.gov> <1992Nov5.051745.7369@linus.mitre.org>
  9. Date: Thu, 5 Nov 1992 18:48:31 GMT
  10. Lines: 75
  11.  
  12. In article <1992Nov5.051745.7369@linus.mitre.org>, crawford@boole.mitre.org (Randy Crawford) writes:
  13. |> [...]
  14. |> As many have pointed out, C has arrays.  When you prefer to use an array
  15. |> in C, you can and should.  To quote the bards K&R, "pointers are not arrays".
  16. |> (If they didn't say that, some other wise soul surely has.)
  17.  
  18. When I pass a multidimensional array to a procedure as an argument,
  19. C turns it into a pointer to the base type of the array.  If the
  20. various dimensions of that array are variable, C does *NOT* permit
  21. it to be declared as a conformable array in the procedure.  Period.
  22. I can cite the restriction directly from the standard document if you'd
  23. like.
  24.  
  25. C has actually committed two sins against array users - both as a
  26. result of this coercion to pointer.  First, it is not notationally
  27. convenient in C to program procedures which handle variable sized
  28. conformable arrays.  Second, the coercion to pointer makes it 
  29. impossible for the C compiler to *locally* determine whether 
  30. incoming pointers are aliased.  If the user were offered a choice,
  31. then he could declare the incoming arguments as pointers if he
  32. wanted to *allow* aliasing, and he could declare them as arrays
  33. (with or without variable dimensions) when he wanted to disallow
  34. aliasing.
  35.  
  36. |> [...]
  37. |> As for using pointers for dynamic memory access or dynamically extensible
  38. |> data structures -- "a rose is a rose by any other name". [...]
  39.  
  40. Except that a pointer `rose' is redolent with the stench of allowed
  41. aliasing while Fortran 90's ALLOCATABLE variables (for example)
  42. are *NOT*.  Similar high-level data structures (like sequences,
  43. trees, etc.) could be defined with similar advantages.  Internally,
  44. these would still probably be implemented with pointers *PLUS*
  45. a constraint against operations which could cause aliasing which
  46. pointers don't provide.  This *exactly* corresponds to the idea
  47. of hiding GOTOs under structures like WHILE, IF/ELSE/ENDIF, 
  48. SELECT/CASE, etc..  The GOTOs are still there *PLUS* constraints
  49. which make the code easier to read and maintain as well as making
  50. the code easier for the compiler to optimize.
  51.  
  52. |> >[...]
  53. |> >Pointers are the GO TO of data structuring.  They are used to create
  54. |> >spaghetti data structures in the same way GO TO is used to create
  55. |> >spaghetti code.  If it's at all possible to avoid using them, don't
  56. |> >use them.  As with GO TO, you only use 'em when you GOT TO.  Also,
  57. |> >as with GO TO, there are ways to make your use more structured if
  58. |> >you *must* use them.
  59. |> 
  60. |> In my opinion, no language leads to worse spaghetti-like data structures 
  61. |> than Lisp, a language without pointers and dependent on garbage collection
  62. |> to do for the programmer what s/he prefers not to do.  That's swell.  For
  63. |> those (like yourself) who prefer to let the language dictate efficiency,
  64.  
  65. On the contrary, I *DEMAND* that the user have control over efficiency
  66. as directly as possible.  One of the most severe *killers* of efficiency 
  67. is the fact that pointers *might* be aliased and the compiler cannot 
  68. tell - so it *must* inhibit optimizations.  I oppose C because it 
  69. *denies* me control that I believe it is important to have.  I don't
  70. say that languages shouldn't have pointers/GOTOs, I just think the
  71. user should have the choice to use additional structures with more 
  72. directly optimizable semantics than these raw tools.
  73.  
  74. |> [...]
  75. |> If the justification for avoiding gotos appears to you to be equivalent 
  76. |> to the rationale behind pointer use, you really should get away from C as 
  77. |> quickly as possible.
  78.  
  79. No, the justification for avoiding GOTOs doesn't just appear to me
  80. to be equivalent to the rational behind pointer *avoidance*, there
  81. is a demonstrable one-to-one correspondance between the two concepts.
  82. If you disagree, take it up with C.A.R. Hoare - who I'm more inclined
  83. to believe than you.
  84.  
  85. -- 
  86. J. Giles
  87.