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

  1. Path: sparky!uunet!sun-barr!ames!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: 28 Aug 1992 15:03:03 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 24
  8. Message-ID: <17lf77INN3nk@early-bird.think.com>
  9. References: <1992Aug27.135946.6622@infonode.ingr.com> <17islrINNh6c@early-bird.think.com> <1992Aug27.181844.11739@email.tuwien.ac.at>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <1992Aug27.181844.11739@email.tuwien.ac.at> hp@vmars.tuwien.ac.at (Peter Holzer) writes:
  13. >barmar@think.com (Barry Margolin) writes:
  14. >>for (_i=(char *)a; _i<a+1000*sizeof(int); _i+=sizeof(int))
  15. >>    *(int *)_i = whatever();
  16. >>I would epect this to produce almost identical code.  And in a language
  17. >>where pointers weren't typed, you wouldn't need all the casting.
  18. >You would still have to cast _i to (int *), or the compiler couldn't
  19. >know how much memory it should access (1 byte? 1 word? ...)
  20.  
  21. Declaring pointers doesn't allocate memory.
  22.  
  23. >Anyway, why should I type sizeof(int), when the compiler can do it for
  24. >me?
  25.  
  26. Several people seem to have misunderstood the point of my posting.  I'm not
  27. recommending the above code.  I was just showing how you would do it if C
  28. didn't have this feature.  I was responding to a post that said that typed
  29. pointers are *necessary* to be able to step a pointer through an array.
  30.  
  31. -- 
  32. Barry Margolin
  33. System Manager, Thinking Machines Corp.
  34.  
  35. barmar@think.com          {uunet,harvard}!think!barmar
  36.