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

Discussion in 'C++' started by ken, Nov 7, 2003.

  1. ken

    ken Guest

    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
    ken, Nov 7, 2003
    #1
    1. Advertising

  2. Re: ISO C++ forbids casting between pointer-to-function andpointer-to-object

    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
    Karl Heinz Buchegger, Nov 7, 2003
    #2
    1. Advertising

  3. ken

    ken Guest

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

    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
    ken, Nov 7, 2003
    #3
  4. ken

    Rolf Magnus Guest

    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.
    Rolf Magnus, Nov 8, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik S. Hansen
    Replies:
    2
    Views:
    51,452
    Alf P. Steinbach
    May 2, 2004
  2. danny van elsen
    Replies:
    6
    Views:
    3,693
    Pete Becker
    May 7, 2005
  3. Penn
    Replies:
    4
    Views:
    1,368
    =?ISO-8859-1?Q?Sch=FCle_Daniel?=
    Jan 9, 2006
  4. BarryKamp
    Replies:
    0
    Views:
    601
    BarryKamp
    Apr 25, 2007
  5. Ravi
    Replies:
    7
    Views:
    1,029
    bodenstorfer
    Jul 30, 2011
Loading...

Share This Page