0 or 0L for empty pointers?
Thiago Macieira
thiago at kde.org
Fri Jun 23 14:29:13 BST 2006
Lubos Lunak wrote:
>On Friday 23 June 2006 14:03, Stefan Teleman wrote:
>> On Friday 23 June 2006 07:42, Frans Englich wrote:
>> > Yes, some features should be avoided
>> > in any case like dynamic_cast, but perhaps there's some template
>> > features or the like that should be avoided.
>>
>> Just out of curiosity, why is dynamic_cast<> a Bad Thing(TM) ?
>
> It is not, in general. But one needs to be careful when using
> dynamic_cast across dlopen boundaries, because under some conditions
> g++ emits multiple rtti info instances which are not merged without
> using RTLD_GLOBAL and that may make dynamic_cast fail. It should be
> fixable though.
In other words, you can only dynamic_cast to type T from type T2 provided
that:
- T is defined in a library you link to
(you'd get a linker error if this isn't the case, since it won't find
the vtable or RTTI info)
- T is "well-anchored" in that library
By "well-anchored" I mean that the vtable is not a COMMON symbol subject
to merging at run-time by the dynamic linker. In other words, the first
virtual member in the class definition must exist and not be inlined: it
must be in a .cpp file.
- T and T2 are exported
We've seen some hard-to-track problems in non-KDE C++ code we're linking
with (I think NMM) because of that. It happened that:
libphonon loads the NMM plugin
NMM plugin links to NMM
NMM loads its own plugins
NMM's own plugins link to NMM
Some classes in the NMM library did not have well-anchored vtables, so
dynamic_casting failed inside the Phonon NMM plugin for objects created
in the NMM's own plugins.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
thiago.macieira (AT) trolltech.com Trolltech ASA
GPG: 0x6EF45358 | Sandakerveien 116,
E067 918B B660 DBD1 105C | NO-0402
966C 33F5 F005 6EF4 5358 | Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20060623/f1ae979c/attachment.sig>
More information about the kde-core-devel
mailing list