home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 13154 < prev    next >
Encoding:
Text File  |  1992-09-03  |  2.0 KB  |  53 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!newsserver.pixel.kodak.com!psinntp!psinntp!rlyeh.multisys.com!rot
  3. From: rot@multisys.com (Republic of Taiwan)
  4. Subject: Re: Why should POINTERS be so damn hard to understand ?
  5. Message-ID: <Btx3II.Fyn@multisys.com>
  6. Organization: Multimedia Information Systems Corporation, San Jose, CA                        TEL: (408) 437-3031            E-mail: info@multisys.com
  7. References: <25233@castle.ed.ac.uk> <1992Aug27.135946.6622@infonode.ingr.com> <1992Aug28.163724.11581@mccc.edu>
  8. Date: Tue, 1 Sep 1992 20:56:41 GMT
  9. Lines: 42
  10.  
  11. In article <1992Aug28.163724.11581@mccc.edu> pjh@mccc.edu (Pete Holsberg) writes:
  12. =In article <1992Aug27.135946.6622@infonode.ingr.com> henders@infonode.ingr.com (Greg Henderson) writes:
  13. ==Well one reason that pops to mind is the nice ability to use a pointer 
  14. ==to traverse an array more efficently than the 'normal' way.  For ex...
  15. ==
  16. ==You could do this normally:
  17. =={
  18. ==    int a[1000], i; 
  19. ==
  20. ==    for ( i=0; i<1000; i++ )
  21. ==    a[i] = get_some_arbitrary_value();
  22. ==}
  23. ==
  24. ==Or you could do this w/ a pointer:
  25. =={
  26. ==    int a[1000], *_i;
  27. ==
  28. ==    for (_i=a;  _i<a+1000; _i++ )
  29. ==    *_i = get_some_arbitrary_value();
  30. ==}
  31. ==
  32. ==These two pieces of code do the exact same thing, but if you are 
  33. ==worried about low-level efficiency the second version is a little
  34. ==tighter, as each reference to the array value in the pointer version
  35. ==requires less work to come up w/ that address.
  36.  
  37. The presumption here is that the length of int is same as
  38. the length of the address space.
  39.  
  40. If the int is 4 byte long and the address space is 2(or 8 or 3) byte long,
  41. the this fell miserably. The second one is not portable.
  42.  
  43. =
  44. =Isn't that a function of the compiler? In fact, let me ask why don't we
  45. =have compilers that produce the most efficient code even when array
  46. =notation is used? Is it that they would be too slow? I recall a FORTRAN
  47. =compiler for a 16-bit digital computer used in a hybrid computer system
  48. =back in the 60s that produced wonderful code, but took a very very long
  49. =time to do it.
  50. =
  51.  
  52.  
  53.