pointer comparisons in dpANS C

T. William Wells bill at twwells.uucp
Mon Oct 24 04:50:03 AEST 1988


In article <14061 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
: [followups redirected to comp.std.c]
: In article <8696 at smoke.ARPA> gwyn at smoke.ARPA (Doug Gwyn) writes:
: >The key is that you are allowed to portably compare pointers only in two
: >cases:  at least one pointer is a null pointer, or both pointers are
: >pointers into the same object.  This means that the fact that p1==p2 for
: >pointers to distinct objects is not a problem, since such comparison is
: >"undefined". ...
:
: This point (which is true) makes me wonder about something.  Consider
: a program which allocates object memory with `malloc'.  Each object has
: pointers to other objects, but does not have backpointers---e.g.,
: a singly linked list.  Now we have a removal routine:

Guys, you are going to have to convince me of this. From everything I
see, two pointers are not allowed to compare equal *unless* they
point to the same object.  Section 3.3.9 is very clear on this point.

It is only for tests other than equality or nonequality that the
pointers must point within the same object.

---
Bill
{uunet|novavax}!proxftl!twwells!bill



More information about the Comp.std.c mailing list