On Saturday 26 September 2009 17:28:49 Christian O'Reilly wrote:
> Hi,
>
> I'm trying to compite boostpythongenerator-0.3 under windows (with MinGW,
> gcc 3.4.5). I get an error ("error ISO C++ forbids casting between
> pointer-to-function and pointer-to-object") on line 124 of the file
> main.cpp. The line in questions is included in the code section below :
>
> 122 if (!generatorSet.isEmpty()) {
> 123 QLibrary plugin(generatorSet+"_generator");
> 124 getGeneratorsFunc getGenerators =
> reinterpret_cast<getGeneratorsFunc>(plugin.resolve("getGenerators"));
> 125 if (getGenerators)
> 126 generators = getGenerators();
> 127 else {
> 128 std::cerr << argv[0] << ": Error loading generatorset
> plugin: " << qPrintable(plugin.errorString()) << std::endl;
> 129 return EXIT_FAILURE;
> 130 }
> 131 }
>
> I'm not sure what to do about it. QLibrary::resolve does return a void*
> which the code try to cast to a function pointer (i.e.getGeneratorsFunc is
> defined by "typedef QLinkedList<Generator*> (*getGeneratorsFunc)();") ans
> this does seem not to be a portable line of code (you may read the
> discussion on
> http://www.velocityreviews.com/forums/t288899-reinterpret-cast-problem.html
> ).
>
> Any idea?I didn't known about this issue with some platforms, the link you sent has many useful comments, the last one is the best and elucidate any doubts on the subject: >> 1. What is the sanctified way to write this type of code. > > There isn't any. There is absolutely no defined conversion between a > pointer to any type of object and a pointer to any type of function. > Not in either C or C++. > > And in fact there are implementations where such conversions are > literally impossible, as pointers to functions are wider than pointers > to any type of object. Bits are truncated and there is no way to get > them back. > > > 2. What is the rational behind the GNU compiler message ( presuming the > > compiler is correctly interpreting the standard). > > The rational is that in C++, as inherited from C, there are objects > and there are functions. They are apples and oranges, they do not > mix. In either language, conversion of a pointer to function to a > pointer to object, in either direction, with or without a cast, is > completely undefined. > > The real problem is sloppy interfaces, both in Windows and *nix, where > they use a pointer to void to hold pointers to functions. This is not > and never has been defined behavior. A union of two pointers could > have been used with no runtime overhead in either execution time or > space on implementations where the two types are the same size, but > it's probably too late now. As Qt is not aware of this problem, we can do nothing about it, however we can replace the reinterpret_cast by a C style cast to avoid compiler errors. Using C-style cast is not the ideal solution, bu at least is a guarantee that it works on all Qt supported platforms, and this is what we want. I'll do this modification, maybe Monday, maybe tomorrow. Thanks for help us. -- Hugo Parente Lima "Precisamos de mais gĂȘnios humildes no mundo, hoje somos poucos!" JID: [email protected]
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ PySide mailing list [email protected] http://lists.openbossa.org/listinfo/pyside
