home *** CD-ROM | disk | FTP | other *** search
- 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
- From: bketcham@stein.u.washington.edu (Benjamin Ketcham)
- Newsgroups: comp.lang.c
- Subject: Re: Pointer math (was Re: adding strings together)
- Date: 6 Jan 1993 07:23:03 GMT
- Organization: University of Washington, Seattle
- Lines: 36
- Message-ID: <1ie1cnINN350@shelley.u.washington.edu>
- References: <1iab6dINNsq9@shelley.u.washington.edu> <C0E3Js.KIG@ocsmd.ocs.com>
- NNTP-Posting-Host: stein.u.washington.edu
-
- In article <C0E3Js.KIG@ocsmd.ocs.com> ted@ocsmd.ocs.com (Ted Scott) writes:
- >Benjamin Ketcham (bketcham@stein.u.washington.edu) wrote:
- >: It's illegal to perform addition on pointers.
- >
- >'Tisit? consider:
-
- [example of adding an integer to a pointer deleted]
-
- >Looks like addition and subtraction to me :-0
-
- >I contend that C will let you do alot without realizing what you're
- >doing. You can add two string pointers together, just don't expect the
- >result to be a concatenated string.
-
- [begin excerpt from K&R2]
-
- The valid pointer operations are assignment of pointers of the same type,
- adding or subtracting a pointer and an integer, subtracting or comparing two
- pointers to members of the same array, and assigning or comparing to zero.
- All other pointer arithmetic is illegal. It is not legal to add two pointers
- ...
-
- [end excerpt from K&R2]
-
- I'm no C genius, but this does seem pretty clear. There's a big difference
- between adding integers to pointers (offsetting), and adding two pointers
- (might be addition of two large 32 bit numbers, who knows?). The original
- poster was referring to wanting to add two pointers, and this is what I was
- saying was illegal. Maybe my original response didn't make clear that I
- was *not* talking about addition of pointers and integers, but this should
- have been clear from the original context.
-
- --ben
-
- PS, I originally tried to respond to the original poster via email, but
- couldn't make connection.
-