Earl Purple wrote: > I have a model whereby I dynamically load libraries with dlopen then > verify that they are the correct types with dynamic_cast.
You can't do that. dlsym() returns a void pointer and that is not something you can safely use dynamic_cast on. If it works, it works because the types are right, if they aren't it might as well crash. The right cast is a simple static_cast. Other than that, there is a known bug that dynamic_cast with objects from shared libraries doesn't work because it compares the type information addresses(!) and those are different because both the main program and the library has a copy of it, but I can't tell you exactly which versions of GCC are affected nor if it really is a GCC error and not a problem with a particular system. > It is vital I use dynamic_cast because reinterpret_cast would of course > lead to undefined behaviour if the type is a mismatch. reinterpret_cast it probably wrong anyway, because it is only guaranteed to return the original value when it was formerly reinterpret_casted to another type. This difference is purely academic though. A simple static_cast is the right thing probably. > And because the name of the symbol to be loaded is read from a > configuration file, there is no possibility of compile-time checks. > > Effectively, is it impossible to do object-broking in this manner using > gcc? Not safely. There are simply too many things that could go wrong or that a malicious plugin could do that it is really hard to check. Why not take a component model in the first place if you need these checks? Uli -- http://gcc.gnu.org/faq.html http://parashift.com/c++-faq-lite/ _______________________________________________ help-gplusplus mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gplusplus
