fuz
fuz

Reputation: 93082

When are pointers to the same object equal?

For two pointers a and b that both point to the same object or function, under which circumstances do the C standards guarantee that a == b? Are there any platforms on which a != b could hold when a and b point to the same object?

Upvotes: 6

Views: 156

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 311058

According to the C Standard (6.5.9 Equality operators from N1548 Committee Draft — December 2, 2010 ISO/IEC 9899:201x)

6 Two pointers compare equal if and only if both are null pointers, both are pointers to the same object (including a pointer to an object and a subobject at its beginning) or function, both are pointers to one past the last element of the same array object, or one is a pointer to one past the end of one array object and the other is a pointer to the start of a different array object that happens to immediately follow the first array object in the address space.109)

Upvotes: 13

Related Questions