Pointer comparison question

Jeffrey_J_Vanepps at cup.portal.com Jeffrey_J_Vanepps at cup.portal.com
Sun Jul 24 09:14:05 AEST 1988


[]

K&R says that you can't reliably compare pointers to one another unless
they both point into the same array. But later they do just that in a
storage allocator. Is this a real discrepancy or am I hallucinating?

I found this because I had to replace the malloc/free functions of
Microsoft C 5.0. Free() does not join adjacent free blocks to form
larger free blocks, and we were suffering fragmentation. Implementing
K&R's malloc/free required casting pointers to (unsigned long) so
they could be compared (it saw some of the pointers as negative when
addresses got up into the 7Fxx:xxxx range).
			  ^^^^^^^^^
			       that's right, ugly segmented address space.

Anyway, I just wondered about the apparent self-contradiction, and if
there was a better way to do this.

	    Jeff Van Epps
	    Jeffrey_J_Vanepps at cup.portal.com

P.S. My sympathy to anyone who is forced to work with either DOS or
     segmented architectures.



More information about the Comp.std.c mailing list