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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ken

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



    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 sFactoryCreatio nFunc =
    ::rtl::OUString ::createFromAsc ii("createDataA ccessToolsFacto ry");>

    - getDbToolsClien tFactoryFunctio n() = reinterpret_cas t<createDataAcc essToolsFactory Function>(>

    + // reinterpret_cas t<createDataAcc essToolsFactory Function> removed for gcc permissive >
    + getDbToolsClien tFactoryFunctio n() = (createDataAcce ssToolsFactoryF unction)(>

    osl_getSymbol(g etDbToolsClient Module(), sFactoryCreatio nFunc.pData));

    Any comments or better solutions appreciated.

    KenF
  • Karl Heinz Buchegger

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



    ken wrote:[color=blue]
    >
    > 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[/color]

    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
    kbuchegg@gascad .at

    Comment

    • ken

      #3
      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:
      [color=blue]
      > 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!"[/color]

      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

      Comment

      • Rolf Magnus

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

        Karl Heinz Buchegger wrote:
        [color=blue]
        >
        >
        > ken wrote:[color=green]
        >>
        >> 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[/color]
        >
        > 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.[/color]

        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.

        Comment

        Working...