Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When are pointers to the same object equal?

Tags:

c

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?

like image 606
fuz Avatar asked Nov 16 '14 18:11

fuz


1 Answers

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)

like image 166
Vlad from Moscow Avatar answered Sep 25 '22 23:09

Vlad from Moscow