home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19297 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  1.9 KB

  1. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!saimiri.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!stein.u.washington.edu!bketcham
  2. From: bketcham@stein.u.washington.edu (Benjamin Ketcham)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointer math (was Re: adding strings together)
  5. Date: 6 Jan 1993 07:23:03 GMT
  6. Organization: University of Washington, Seattle
  7. Lines: 36
  8. Message-ID: <1ie1cnINN350@shelley.u.washington.edu>
  9. References: <1iab6dINNsq9@shelley.u.washington.edu> <C0E3Js.KIG@ocsmd.ocs.com>
  10. NNTP-Posting-Host: stein.u.washington.edu
  11.  
  12. In article <C0E3Js.KIG@ocsmd.ocs.com> ted@ocsmd.ocs.com (Ted Scott) writes:
  13. >Benjamin Ketcham (bketcham@stein.u.washington.edu) wrote:
  14. >: It's illegal to perform addition on pointers. 
  15. >
  16. >'Tisit?  consider:
  17.  
  18. [example of adding an integer to a pointer deleted]
  19.  
  20. >Looks like addition and subtraction to me :-0
  21.  
  22. >I contend that C will let you do alot without realizing what you're
  23. >doing. You can add two string pointers together, just don't expect the 
  24. >result to be a concatenated string.
  25.  
  26. [begin excerpt from K&R2]
  27.  
  28. The valid pointer operations are assignment of pointers of the same type,
  29. adding or subtracting a pointer and an integer, subtracting or comparing two
  30. pointers to members of the same array, and assigning or comparing to zero.
  31. All other pointer arithmetic is illegal.  It is not legal to add two pointers
  32. ...
  33.  
  34. [end excerpt from K&R2]
  35.  
  36. I'm no C genius, but this does seem pretty clear.  There's a big difference
  37. between adding integers to pointers (offsetting), and adding two pointers
  38. (might be addition of two large 32 bit numbers, who knows?).  The original
  39. poster was referring to wanting to add two pointers, and this is what I was
  40. saying was illegal.  Maybe my original response didn't make clear that I
  41. was *not* talking about addition of pointers and integers, but this should
  42. have been clear from the original context.
  43.  
  44. --ben
  45.  
  46. PS, I originally tried to respond to the original poster via email, but
  47. couldn't make connection.
  48.