ISO C++ forbids casting between pointer-to-function and pointer-to-object

K

ken

I am getting this error from a gcc compile and I was wondering whether
this was 100% valid. This seems a little extreme to me the c++ cast
operators appear to only work on objects which defeats the purpose of
them. I had to remove the C++ cast and change to a C one in order for
gcc to accept it, we are using permissive and I am getting rid of it. Is
this truly correct?

const ::rtl::OUString sFactoryCreationFunc =
::rtl::OUString::createFromAscii("createDataAccessToolsFactory");>

- getDbToolsClientFactoryFunction() = reinterpret_cast<createDataAccessToolsFactoryFunction>(>

+ // reinterpret_cast<createDataAccessToolsFactoryFunction> removed for gcc permissive >
+ getDbToolsClientFactoryFunction() = (createDataAccessToolsFactoryFunction)(>

osl_getSymbol(getDbToolsClientModule(), sFactoryCreationFunc.pData));

Any comments or better solutions appreciated.

KenF
 
K

Karl Heinz Buchegger

ken said:
I am getting this error from a gcc compile and I was wondering whether
this was 100% valid. This seems a little extreme to me

read the error message again.

casting between pointer-to-function and pointer-to-object

What good is it to cast a pointer-to-object to a pointer-to-function?
The later points at executable code, while the first points at data.
So why on earth would one want to cast one into another except for
beeing able to get at the opcodes of a function which, unless you are
writting a disassembler or a debugger, is a rather unusual
thing to do. You don't seem to be doing this, so the error message
points more in the direction of: "Hey buddy, there seems to be something
wrong with your pointer types. Check them!"
 
K

ken

casting between pointer-to-function and pointer-to-object

What good is it to cast a pointer-to-object to a pointer-to-function?
The later points at executable code, while the first points at data.
So why on earth would one want to cast one into another except for
being able to get at the opcodes of a function which, unless you are
writing a disassembler or a debugger, is a rather unusual
thing to do. You don't seem to be doing this, so the error message
points more in the direction of: "Hey buddy, there seems to be something
wrong with your pointer types. Check them!"

The code is casting the function to a void to allow the external interface
to be transparent to the user of that interface. I cannot "undesign" the
interface easily like most projects I have to live with it. There is now
a project to clean this up but that is strategic rather than immediate.

There is no object in void and no object in a function call. Poor design
aside I think that there might be a problem with this message.

KenF
 
R

Rolf Magnus

Karl said:
read the error message again.

casting between pointer-to-function and pointer-to-object

What good is it to cast a pointer-to-object to a pointer-to-function?
The later points at executable code, while the first points at data.
So why on earth would one want to cast one into another except for
beeing able to get at the opcodes of a function which, unless you are
writting a disassembler or a debugger, is a rather unusual
thing to do.

A void* is unfortunately also seen as pointer-to-object. Some quite
common interfaces for loading libraries dynamically provide a function
to which you can provide a symbol name as char array, and you get back
a void* that points to it. If it's a function, you have to convert a
void* (i.e. an object pointer) into a function pointer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top