I am checking to see if two references are bound to the same object. My instincts tell Me, "Check their addresses. If they match, they are bound to the same." At the same time, I have not found anything in the C++ standard which would support this approach. Am I missing something? Is there wording which backs up My instincts? Is there a standard function to do this?
Thanks for confirming My instincts but is there specific wording in the standard which makes it so or is there just a presumed convention? I ask because I have some safety-critical code which would depend upon such being behavior standardized.
Unless an object is a bit-field or a base class subobject of zero size, the address of that object is the address of the first byte it occupies. Two objects that are not bit-fields may have the same address if one is a subobject of the other, or if at least one is a base class subobject of zero size and they are of different types; otherwise,
they shall have distinct addresses.
Footnote: Under the “as-if” rule an implementation is allowed to store two objects at the same machine address or not store an object at all if the program cannot observe the difference - IS 1.8 The C++ Object Model