DRAFT document on coding conventions in kde libraries
Thiago Macieira
thiago at kde.org
Sun Mar 12 17:35:00 GMT 2006
Thiago Macieira wrote:
>that's weird...
>$ cat test.cpp
>#include <dlfcn.h>
>
>typedef void (*functype)(int, int);
>
>main()
>{
> void *sym = dlsym(0, 0);
>
> functype f = reinterpret_cast<functype>(sym);
> f = reinterpret_cast<void (*)(int, int)>(sym);
>
> (*f)(1,2);
>}
>$ g++ -c -o test.o test.cpp
>[no errors]
Ok, you're not allowed to write the above test, but you're allowed to
write it this way:
#include <dlfcn.h>
typedef void (*functype)(int, int);
main()
{
void *sym = dlsym(0, 0);
functype f;
*reinterpret_cast<void**>(&f) = sym;
(*f)(1,2);
}
I tested it on the Itanium machine this time :-)
Itanium solves the problem that a function pointer is really two 64-bit
numbers by making dlsym return a pointer to the those two numbers.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
2. Tó cennan his weorc gearu, ymbe se circolwyrde, wearð se cægbord and se
leohtspeccabord, and þa mýs cómon lator. On þone dæg, he hine reste.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20060312/bd664df9/attachment.sig>
More information about the kde-core-devel
mailing list