HP's object layout, clarification

Christophe de Dinechin ddd at cup.hp.com
Mon Jun 14 22:17:03 UTC 1999


Brian Thomson wrote:

> Cary, your object layout description makes this statement:
>
>     The C++ language allows an empty base-class to share
>     its location with its descendents ...
>     ... but also imposes the following INequalities:
>
>     (void*)&empty != (void*)&also_empty
>     (void*)&(Empty2&)bug != (void*)&(AlsoEmpty&)bug
>
>     I.e., for two subobjects to have the same address,
>     one must be derived from the other
>
> I see this asserted in section 10.0 of the spec for subobjects
> "that have the same class type", but not for subobjects in general. 
> Do you have a supporting citation?
>
I think this is 5.10. [expr.eq], which says:

	Pointer to objects or functions of the same type
	(after pointer conversion) can be compared for
	equality. Two pointers of the same type compare
	equal if and only if they are both null, both point
	to the same object or function, or both point one
	past the end of the same array.

Since (void *) is the same type, you can do the comparison.
'empty' and 'also_empty' are not the same object. Similarly, the  
(Empty2) subobject of 'bug' and the (AlsoEmpty) subobject are not the  
same object. In both cases, this means that the equality above  
cannot be true.

What were described as possible equalities are when the objects are  
actually the same. Probably the wording above is not perfect (but,  
remember, this used to be an internal document). Rather than
	for two subobjects to have the same address,
	one must be derived from the other
you could have:
	for two pointers to compare equal,
	they must actually point to the same object.
(which implies the other, but the converse is not true)


Best regards
Christophe de Dinechin.




More information about the cxx-abi-dev mailing list