Article View: comp.std.c
Article #2904pointer comparison
From: Lars Nyman
Date: Wed, 23 Dec 1992 00:14
Date: Wed, 23 Dec 1992 00:14
37 lines
1589 bytes
1589 bytes
There is a thread in comp.std.c++ about comparisons of pointers
to objects that caused me to think about the situation in ANSI C.
I don't have the ANSI C standard and thus resort to ask here.
I *think* there is language in the standard that says something to the
effect that comparisons of pointers to two objects that are NOT
members of the same aggregate or union object is undefined (with
one exception - one or both pointers pointing past the last object
of an array).
So, if I have two different objects of same type, and they are not
in the same array or aggregate, the result of comparing pointers to
them is undefined !!???
Which would mean that in the following trivial code:
typedef struct { int i; } foo;
foo f1, f2;
foo* pF1 = &f1;
foo* pF2 = &f2;
assert( pF1 != pF2 );
the value of 'pF1 != pF2' is undefined and the assertion may/can fail !!!
Can somebody, please, correct me and tell me what I am overlooking.
What in the standard guarantees that pointers to two different objects
are guaranteed to compare unequal ?
Lars Nyman
(*If* my reasoning is correct... wouldn't this also allow malloc(0) to
return whatever it wants, including repeatedly the same value (except
maybe for NULL), since the result of a comparison between any two pointers
obtained by malloc() would be undefined).
Technical Details
Message-ID:
<18221@autodesk.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!autodesk!larsnShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!autodesk!larsn From: larsn@Autodesk.COM (Lars Nyman) Newsgroups: comp.std.c Subject: pointer comparison Message-ID: <18221@autodesk.COM> Date: 23 Dec 92 00:14:52 GMT Sender: news@Autodesk.COM Lines: 37