Path: utzoo!attcan!uunet!mcvax!hp4nl!orcenl!bengsig From: bengsig@oracle.nl (Bjorn Engsig) Newsgroups: comp.lang.c Subject: Re: Adding two pointers Message-ID: <325.nlhp3@oracle.nl> Date: 11 May 89 12:07:12 GMT References: <2765@buengc.BU.EDU> <563@lzaz.ATT.COM> <4093@ficc.uu.net> <922@garcon.cso.uiuc.edu> <924@garcon.cso.uiuc.edu> <113@ssp1.idca.tds.philips.nl> <1321@infmx.UUCP> Reply-To: bengsig@oracle.nl (Bjorn Engsig) Organization: ORACLE Europe, The Netherlands Lines: 35 In article <1321@infmx.UUCP> kevinf@infmx.UUCP (Kevin Franden) writes: = = struct{...}foo; = = foo *p1,*p2,*p3; /* I added the *'s in the above declarations */ /* And I would add the following: */ int x,y; = = x=37; = y=4; = = p1=a[x]; = p2=a[y]; = p3=(x+y)*sizeof(foo); = = I realize that I missed part of this discussion, sorry if this has been = posted already, but won't p3 be pointing to the 41st element? Hmm, yes, but the construct is highly debatable ... = if this =is true, this is pointer addition, no? No, it's integer addition, and a highly debatable computation of a pointer, and an assignment which needs a cast. In pointer arithmetic, you can achieve what you are trying by p3 = p2 + (p1 - a) which means let p3 equeal the current p2 plus the number of elements between p1 and the beginning of the array a. Note, however that this is a pointer plus an integer, the latter being the difference between two pointers. -- Bjorn Engsig, ORACLE Europe \ / "Hofstadter's Law: It always takes Path: mcvax!orcenl!bengsig X longer than you expect, even if you Domain: bengsig@oracle.nl / \ take into account Hofstadter's Law"