pointer comparisons in dpANS C

Chip Salzenberg chip at ateng.ateng.com
Sat Oct 22 04:36:39 AEST 1988


According to chris at mimsy.UUCP (Chris Torek):
[sample program deleted]
>Every address returned by malloc must compare as not distinct from
>every other address, lest this routine delete the wrong object.

Quite.

As a data point:  C compilers for the '286, when generating "far" pointers
(16 bits segment, 16 bits offset), generally ignore the segment portion of
pointers when testing their relative magnitudes ("<", ">=", etc).  However,
tests for equality and inequality ("==", "!=") always compare all 32 bits.

I understand why this choice might be made, and it certainly passes Henry's
test program.  Nevertheless, it can be surprising -- perhaps incorrect? --
that:

	((p >= q) && (p <= q))

is not the same as:

	(p == q)

Ah well, yet another '286 "feature".
-- 
Chip Salzenberg             <chip at ateng.com> or <uunet!ateng!chip>
A T Engineering             Me?  Speak for my company?  Surely you jest!
	   Beware of programmers carrying screwdrivers.



More information about the Comp.std.c mailing list