home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19594 < prev    next >
Encoding:
Text File  |  1993-01-12  |  2.2 KB  |  53 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mccall
  3. From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
  4. Subject: Re: Moving from Pascal to C, Help please!!!!!! 
  5. Message-ID: <1993Jan12.190826.20740@mksol.dseg.ti.com>
  6. Organization: Texas Instruments Inc
  7. References: <4293@dozo.and.nl> <726510754snz@panache.demon.co.uk>
  8. Date: Tue, 12 Jan 1993 19:08:26 GMT
  9. Lines: 42
  10.  
  11. In <726510754snz@panache.demon.co.uk> raph@panache.demon.co.uk (Raphael mankin) writes:
  12.  
  13. >In article <4293@dozo.and.nl> jos@and.nl writes:
  14.  
  15. >>
  16. >>Another way to approach pointer arithmetic is first to convert the
  17. >>pointer(s) to character pointer(s): [ ... ] For pointer subtracion,
  18. >>the result of the difference between the character pointers is 
  19. >>similarly divided by the size of the object originally pointed to.
  20. >>
  21.  
  22. >IMHO the only thing one can say about pointer arithmetic is DON'T.
  23.  
  24. There's singularly bad advice from someone with that much experience.
  25.  
  26. >Regardless of what K&R or the standard say about its legality, tinkering
  27. >with pointers is one of the surest ways of getting into trouble. 30 years
  28. >of programming, in more languages than most readers of this group have even
  29. >heard of, has led me to this position.
  30.  
  31. Then your experience hasn't been in C, in which arrays are NOT
  32. first-class objects.  'Tinkering' with pointers is one of the basic
  33. building blocks in the language.
  34.  
  35. >If your pointer points to an array, use subscripting. Let the compiler's
  36. >optimiser work out whether there are really better ways of doing the job.
  37.  
  38. And what do you do when a pointer is passed to a function?  Punt?
  39.  
  40. >If your pointer is to a single item, then the only thing you should do with it
  41. >is to follow it (dereference).
  42.  
  43. You may have a lot of experience in things most people have never
  44. heard of (although I'd bet that a lot of us could probably say the
  45. same to you), but you don't appear to have sufficient experience in C
  46. to be making such statements.
  47.  
  48. -- 
  49. "Insisting on perfect safety is for people who don't have the balls to live
  50.  in the real world."   -- Mary Shafer, NASA Ames Dryden
  51. ------------------------------------------------------------------------------
  52. Fred.McCall@dseg.ti.com - I don't speak for others and they don't speak for me.
  53.