Pointers-to-members
Mark Mitchell
mark at codesourcery.com
Tue Feb 22 22:01:50 UTC 2000
>>>>> "Jason" == Jason Merrill <jason at cygnus.com> writes:
Jason> My guess would be that casting is more common than
Jason> comparison, though I have no data for that.
I agree. That's in keeping with my second posting on this topic,
where I realized that making both fields be zero would penalize
casting:
It's occurred to me that this imposes some overhead on casting
pointers-to-members around: now when you convert from a base pointer
to member to a derived version (or vice versa), you can't just adjust
the `adj' member willy-nilly; instead, you have to check first whether
or not the pointer is NULL.
So, it would be helpful if we were to add:
(Note: the `adj' field is not necessarily zero even when the
pointer-to-member is NULL. Therefore, casting a
pointer-to-derived-member to a pointer-to-base-member (or vice
versa) requires only an adjustment to the `adj' field. However,
comparsion of two pointers-to-members requires more than
a bitwise comparision. Code equivalent to:
p1.ptr == p2.ptr && (!p1.ptr || (p1.adj == p2.adj))
is required since in the case that p1.ptr and p2.ptr are both
zero, there `adj' fields are irrelevant.)
to the ABI document.
Jason> Also, we can
Jason> optimize comparison to NULL by ignoring the adjustment
Jason> entirely.
True -- in either scheme. But an additional argument in favor of the
above resolution.
Thanks,
--
Mark Mitchell mark at codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
More information about the cxx-abi-dev
mailing list