Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!udel!udccvax1!gdtltr From: gdtltr@vax1.acs.udel.EDU (Gary D Duzan) Newsgroups: comp.lang.c Subject: Re: Adding two pointers Message-ID: <3596@udccvax1.acs.udel.EDU> Date: 11 May 89 00:06:37 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: gdtltr@vax1.acs.udel.EDU (Gary D Duzan) Organization: Galadrim (really a disorganization) Lines: 48 In article <1321@infmx.UUCP> kevinf@infmx.UUCP (Kevin Franden) writes: => =>Assuming that there does exist an application that wnats/needs to add =>pointers, why won't this 'model' work? => => Assume an array a to be made up of elements of => arbitrary size. Assume further that this array has => 100 elements arranged (as we know C does) contiguously => in memory. => => if p1 is pointing to element 37 and p2 is pointing to => element 4, I'd like p3 to point to a[37+4] or a[41]. => => struct{...}foo; => => foo p1,p2,p3; => => 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? if this =>is true, this is pointer addition, no? => No. I believe what you want is a[x+y] . p3 will be the number of bytes taken up by x+y elements of foo. You also might be thinking a+x+y . This should be legal and do what you want. Sorry if I am incorrect here, but I am a bit new to C myself. This is a bit odd when you consider the fact that I am trying to put together a minimal K&R C compiler (don't ask for what machine, you'll just laugh). Gary Duzan Time Lord Third Regeneration -- +------------------------------------------+ UUCP: !uunet!udel.edu!vax1!gdtltr | "Two hearts are better than one." -- Yes | Internet: gdtltr@vax1.acs.udel.edu | "Don't listen to me; I never do." -- Doctor Who | Other: Relay through CUNYVM +-------------------------------------------------+ or something.