home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12854 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.3 KB  |  37 lines

  1. Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!yale.edu!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Why should POINTERS be so damn hard to understand ?
  5. Date: 27 Aug 1992 15:34:19 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 25
  8. Message-ID: <17islrINNh6c@early-bird.think.com>
  9. References: <l9nl34INNhln@almaak.usc.edu> <25233@castle.ed.ac.uk> <1992Aug27.135946.6622@infonode.ingr.com>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <1992Aug27.135946.6622@infonode.ingr.com> henders@infonode.ingr.com (Greg Henderson) writes:
  13. >    int a[1000], *_i;
  14. >    for (_i=a;  _i<a+1000; _i++ )
  15. >    *_i = get_some_arbitrary_value();
  16. >[This] version would not be possible unless you had pointers that
  17. >knew what type they were supposed to point to, and thus know how many
  18. >bytes to increment the address to get to next guy.
  19.  
  20. That's not true.  If pointers didn't scale automatically, the programmer
  21. would do it himself:
  22.  
  23. int a[1000];
  24. char *_i;
  25.  
  26. for (_i=(char *)a; _i<a+1000*sizeof(int); _i+=sizeof(int))
  27.     *(int *)_i = whatever();
  28.  
  29. I would epect this to produce almost identical code.  And in a language
  30. where pointers weren't typed, you wouldn't need all the casting.
  31.  
  32. -- 
  33. Barry Margolin
  34. System Manager, Thinking Machines Corp.
  35.  
  36. barmar@think.com          {uunet,harvard}!think!barmar
  37.