home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12920 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  1.5 KB

  1. Path: sparky!uunet!stanford.edu!rutgers!princeton!mccc!pjh
  2. From: pjh@mccc.edu (Pete Holsberg)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Why should POINTERS be so damn hard to understand ?
  5. Message-ID: <1992Aug28.163724.11581@mccc.edu>
  6. Date: 28 Aug 92 16:37:24 GMT
  7. References: <l9nl34INNhln@almaak.usc.edu> <25233@castle.ed.ac.uk> <1992Aug27.135946.6622@infonode.ingr.com>
  8. Organization: The College On The Other Side Of Route One
  9. Lines: 31
  10.  
  11. In article <1992Aug27.135946.6622@infonode.ingr.com> henders@infonode.ingr.com (Greg Henderson) writes:
  12. =Well one reason that pops to mind is the nice ability to use a pointer 
  13. =to traverse an array more efficently than the 'normal' way.  For ex...
  14. =
  15. =You could do this normally:
  16. ={
  17. =    int a[1000], i; 
  18. =
  19. =    for ( i=0; i<1000; i++ )
  20. =    a[i] = get_some_arbitrary_value();
  21. =}
  22. =
  23. =Or you could do this w/ a pointer:
  24. ={
  25. =    int a[1000], *_i;
  26. =
  27. =    for (_i=a;  _i<a+1000; _i++ )
  28. =    *_i = get_some_arbitrary_value();
  29. =}
  30. =
  31. =These two pieces of code do the exact same thing, but if you are 
  32. =worried about low-level efficiency the second version is a little
  33. =tighter, as each reference to the array value in the pointer version
  34. =requires less work to come up w/ that address.
  35.  
  36. Isn't that a function of the compiler? In fact, let me ask why don't we
  37. have compilers that produce the most efficient code even when array
  38. notation is used? Is it that they would be too slow? I recall a FORTRAN
  39. compiler for a 16-bit digital computer used in a hybrid computer system
  40. back in the 60s that produced wonderful code, but took a very very long
  41. time to do it.
  42.