Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > ISO C++ forbids casting between pointer-to-function and pointer-to-object

Reply
Thread Tools

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

 
 
ken
Guest
Posts: n/a
 
      11-07-2003


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("createDataAccess ToolsFactory");>

- getDbToolsClientFactoryFunction() = reinterpret_cast<createDataAccessToolsFactoryFunct ion>(>

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

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

Any comments or better solutions appreciated.

KenF
 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      11-07-2003


ken wrote:
>
> 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!"


--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
ken
Guest
Posts: n/a
 
      11-07-2003
On Fri, 07 Nov 2003 14:38:42 +0100, Karl Heinz Buchegger wrote:

> 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
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      11-08-2003
Karl Heinz Buchegger wrote:

>
>
> ken wrote:
>>
>> 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.


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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ISO C++ forbids "set" and "get" as method names? Ravi C++ 7 07-30-2011 01:00 PM
ISO C++ forbids comparison between pointer and integer BarryKamp C Programming 0 04-25-2007 09:31 PM
ISO C++ forbids declaration of `cout' with no type. Penn C++ 4 01-09-2006 11:47 PM
error: ISO C++ forbids cast to non-reference type used as lvalue danny van elsen C++ 6 05-07-2005 05:56 PM
ISO C++ forbids declaration of "tst" with no type Henrik S. Hansen C++ 2 05-02-2004 08:38 PM



Advertisments