Adding two pointers

Kevin Franden kevinf at infmx.UUCP
Thu May 11 05:50:27 AEST 1989


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?


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Kevin Franden		    UUCP: {backbone}!pyramid!infmx!kevinf
Informix Software Inc
disclaimer("I said what I said and not my employer");
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Cocaine: The big lie.

OS/2: The BIG hack.



More information about the Comp.lang.c mailing list