TITLE: Are object addresses unique identifiers? PROBLEM: cbarber@bbn.com "Christopher Barber" [...] The ARM states that "objects of an empty class have a nonzero size" (section 9, p164 of the 1st edition). This is so that such objects can be allocated and have [unique] addresses. RESPONSE: Mark Strange Yes, empty classes have a size of 1. You are correct in saying that it is so that they are given an address. Since each object, even 'empty' ones have an address, it is possible to distinguish, by comparing addresses, between objects of the same class. RESPONSE: jamshid@ses.com (Jamshid Afshar), 18 Sep 94 I wish C++ guaranteed this to be true, but last I heard it will not. Of course I'm not talking about comparing addresses after casting them to void*. The first member of a struct is guaranteed to be at the same (void*) address as the enclosing object and the first member of an array is at the same address as the array itself. I'm referring to comparisons involving standard conversions (no casts) like: class B {}; class D1 : public B {}; class D2 : public B { D1 d1; }; D2 d2; D1* p1 = &d2.d1; // pointer to subobject D2* p2 = &d2; As far as I know, a compiler may make `p1' equal `p2' even though they are *not* pointing to the "same" object (by an practical definition of "same"). How could this cause a problem in real code? Say the B constructor stores `this' in a static Set to keep track of all "live" B objects. If B::~B() removes `this' from the set, we would get an error when d2 is destroyed because the destructors for both d2 and d2.d1 would try to remove the same B* address from the set. Yes, B would usually have a virtual function or destructor and because of the vtable pointer the compiler could not optimize away the object's size, but a vtable pointer is not the only way for a C++ compiler to implement polymorphism. Has ANSI/ISO looked into this problem?