A Question that really bothers me...

Discussion in 'C++' started by j1230xz@gmail.com, Feb 26, 2008.

  1. Guest

    Ok now the problem is this.

    I have compiled some old code with Visual Studio 2008 (the code was
    originally writen in Visual Studio 6) and i have this error:

    Error 1 error C2681: 'void *' : invalid expression type for
    dynamic_cast c:\Works\BaCCTester\Dev\Addins\Utils
    \CommonDataManipulators\Sources\CommonDataFree.cpp 121
    CommonDataManipulators

    and the problematic line of code is this:
    ....
    FunctionResponse* pFunctionResponse =
    ACE_dynamic_cast(FunctionResponse*, data);
    ....

    So it is logicaly that dynamic_cast does not work for void-pointers
    since when I converted the pointer to void I have given up all type
    information. But what makes me think twice about the corectness of the
    previous sentence is that this code compiles perfectly under Visual
    Studio 6. I would like to know more about this issue so any help,
    references, links and so are highly appriciated.

    Thank You,
    Nikola Tanev
    , Feb 26, 2008
    #1
    1. Advertising

  2. Guest

    ONE MORE THINK TO ADD:
    RTTI is turned ON

    On Feb 26, 10:33 am, "" <> wrote:
    > Ok now the problem is this.
    >
    > I have compiled some old code with Visual Studio 2008 (the code was
    > originally writen in Visual Studio 6) and i have this error:
    >
    > Error 1 error C2681: 'void *' : invalid expression type for
    > dynamic_cast c:\Works\BaCCTester\Dev\Addins\Utils
    > \CommonDataManipulators\Sources\CommonDataFree.cpp 121
    > CommonDataManipulators
    >
    > and the problematic line of code is this:
    > ...
    > FunctionResponse* pFunctionResponse =
    > ACE_dynamic_cast(FunctionResponse*, data);
    > ...
    >
    > So it is logicaly that dynamic_cast does not work for void-pointers
    > since when I converted the pointer to void I have given up all type
    > information. But what makes me think twice about the corectness of the
    > previous sentence is that this code compiles perfectly under Visual
    > Studio 6. I would like to know more about this issue so any help,
    > references, links and so are highly appriciated.
    >
    > Thank You,
    > Nikola Tanev
    , Feb 26, 2008
    #2
    1. Advertising

  3. James Kanze Guest

    On Feb 26, 10:33 am, "" <> wrote:
    > Ok now the problem is this.


    > I have compiled some old code with Visual Studio 2008 (the
    > code was originally writen in Visual Studio 6) and i have this
    > error:


    > Error 1 error C2681: 'void *' : invalid expression type for
    > dynamic_cast c:\Works\BaCCTester\Dev\Addins\Utils
    > \CommonDataManipulators\Sources\CommonDataFree.cpp 121
    > CommonDataManipulators


    > and the problematic line of code is this:
    > ...
    > FunctionResponse* pFunctionResponse =
    > ACE_dynamic_cast(FunctionResponse*, data);
    > ...


    > So it is logicaly that dynamic_cast does not work for
    > void-pointers since when I converted the pointer to void I
    > have given up all type information. But what makes me think
    > twice about the corectness of the previous sentence is that
    > this code compiles perfectly under Visual Studio 6. I would
    > like to know more about this issue so any help, references,
    > links and so are highly appriciated.


    The real question is what ACE_dynamic_cast is. I suspect that
    it's a macro, and probably expands differently depending on the
    compiler, but I really don't know.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Feb 26, 2008
    #3
  4. Guest

    On Feb 26, 11:37 am, James Kanze <> wrote:
    > On Feb 26, 10:33 am, "" <> wrote:
    >
    >
    >
    > > Ok now the problem is this.
    > > I have compiled some old code with Visual Studio 2008 (the
    > > code was originally writen in Visual Studio 6) and i have this
    > > error:
    > > Error 1 error C2681: 'void *' : invalid expression type for
    > > dynamic_cast c:\Works\BaCCTester\Dev\Addins\Utils
    > > \CommonDataManipulators\Sources\CommonDataFree.cpp 121
    > > CommonDataManipulators
    > > and the problematic line of code is this:
    > > ...
    > > FunctionResponse* pFunctionResponse =
    > > ACE_dynamic_cast(FunctionResponse*, data);
    > > ...
    > > So it is logicaly that dynamic_cast does not work for
    > > void-pointers since when I converted the pointer to void I
    > > have given up all type information. But what makes me think
    > > twice about the corectness of the previous sentence is that
    > > this code compiles perfectly under Visual Studio 6. I would
    > > like to know more about this issue so any help, references,
    > > links and so are highly appriciated.

    >
    > The real question is what ACE_dynamic_cast is. I suspect that
    > it's a macro, and probably expands differently depending on the
    > compiler, but I really don't know.
    >
    > --
    > James Kanze (GABI Software) email:
    > Conseils en informatique orientée objet/
    > Beratung in objektorientierter Datenverarbeitung
    > 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


    Yes it is a macro
    # define ACE_dynamic_cast(TYPE, EXPR) dynamic_cast<TYPE> (EXPR)
    actualy it is a standard dynamic_cast and it is from the ACE libraries
    , Feb 26, 2008
    #4
  5. Puppet_Sock Guest

    On Feb 26, 8:18 am, "" <> wrote:
    > On Feb 26, 11:37 am, James Kanze <> wrote:
    >
    > > On Feb 26, 10:33 am, "" <> wrote:

    >
    > > > Ok now the problem is this.
    > > > I have compiled some old code with Visual Studio 2008 (the
    > > > code was originally writen in Visual Studio 6) and i have this
    > > > error:
    > > > Error   1       error C2681: 'void *' : invalid expression type for
    > > > dynamic_cast    c:\Works\BaCCTester\Dev\Addins\Utils
    > > > \CommonDataManipulators\Sources\CommonDataFree.cpp      121
    > > > CommonDataManipulators
    > > > and the problematic line of code is this:
    > > > ...
    > > > FunctionResponse* pFunctionResponse =
    > > > ACE_dynamic_cast(FunctionResponse*, data);
    > > > ...
    > > > So it is logicaly that dynamic_cast does not work for
    > > > void-pointers since when I converted the pointer to void I
    > > > have given up all type information. But what makes me think
    > > > twice about the corectness of the previous sentence is that
    > > > this code compiles perfectly under Visual Studio 6. I would
    > > > like to know more about this issue so any help, references,
    > > > links and so are highly appriciated.

    >
    > > The real question is what ACE_dynamic_cast is.  I suspect that
    > > it's a macro, and probably expands differently depending on the
    > > compiler, but I really don't know.

    >
    > Yes it is a macro
    > #   define ACE_dynamic_cast(TYPE, EXPR) dynamic_cast<TYPE> (EXPR)
    > actualy it is a standard dynamic_cast and it is from the ACE libraries


    <InigoMontoyaVoice>You keep using that word. I do not think
    it means what you think it means.</voice>

    In this news group, "standard" means part of the standard
    C++ language, not part of a commercial library, no matter
    how many people use it.

    As to your original question:
    - Did you read the help files for VS?

    Compiler Error C2681
    > A casting operator tried to convert from an invalid type.
    > For example, if you use the dynamic_cast operator to
    > convert an expression to a pointer type, the source
    > expression must be a pointer.


    - Did you consider asking your question in a news group
    dealing with VS?

    As to what older versions of VS would do: Older versions
    were feydasque but fun. Lots of whacky things they did,
    for many reasons, most of which are a bit off topic here.
    Socks
    Puppet_Sock, Feb 26, 2008
    #5
  6. Guest

    äá á?


    On Feb 26, 5:43 pm, Puppet_Sock <> wrote:
    > On Feb 26, 8:18 am, "" <> wrote:
    >
    >
    >
    > > On Feb 26, 11:37 am, James Kanze <> wrote:

    >
    > > > On Feb 26, 10:33 am, "" <> wrote:

    >
    > > > > Ok now the problem is this.
    > > > > I have compiled some old code with Visual Studio 2008 (the
    > > > > code was originally writen in Visual Studio 6) and i have this
    > > > > error:
    > > > > Error 1 error C2681: 'void *' : invalid expression type for
    > > > > dynamic_cast c:\Works\BaCCTester\Dev\Addins\Utils
    > > > > \CommonDataManipulators\Sources\CommonDataFree.cpp 121
    > > > > CommonDataManipulators
    > > > > and the problematic line of code is this:
    > > > > ...
    > > > > FunctionResponse* pFunctionResponse =
    > > > > ACE_dynamic_cast(FunctionResponse*, data);
    > > > > ...
    > > > > So it is logicaly that dynamic_cast does not work for
    > > > > void-pointers since when I converted the pointer to void I
    > > > > have given up all type information. But what makes me think
    > > > > twice about the corectness of the previous sentence is that
    > > > > this code compiles perfectly under Visual Studio 6. I would
    > > > > like to know more about this issue so any help, references,
    > > > > links and so are highly appriciated.

    >
    > > > The real question is what ACE_dynamic_cast is. I suspect that
    > > > it's a macro, and probably expands differently depending on the
    > > > compiler, but I really don't know.

    >
    > > Yes it is a macro
    > > # define ACE_dynamic_cast(TYPE, EXPR) dynamic_cast<TYPE> (EXPR)
    > > actualy it is a standard dynamic_cast and it is from the ACE libraries

    >
    > <InigoMontoyaVoice>You keep using that word. I do not think
    > it means what you think it means.</voice>
    >
    > In this news group, "standard" means part of the standard
    > C++ language, not part of a commercial library, no matter
    > how many people use it.
    >
    > As to your original question:
    > - Did you read the help files for VS?
    >
    > Compiler Error C2681
    >
    > > A casting operator tried to convert from an invalid type.
    > > For example, if you use the dynamic_cast operator to
    > > convert an expression to a pointer type, the source
    > > expression must be a pointer.

    >
    > - Did you consider asking your question in a news group
    > dealing with VS?
    >
    > As to what older versions of VS would do: Older versions
    > were feydasque but fun. Lots of whacky things they did,
    > for many reasons, most of which are a bit off topic here.
    > Socks
    , Feb 26, 2008
    #6
  7. Bo Persson Guest

    wrote:
    > On Feb 26, 11:37 am, James Kanze <> wrote:
    >> On Feb 26, 10:33 am, "" <> wrote:
    >>
    >>
    >>
    >>> Ok now the problem is this.
    >>> I have compiled some old code with Visual Studio 2008 (the
    >>> code was originally writen in Visual Studio 6) and i have this
    >>> error:
    >>> Error 1 error C2681: 'void *' : invalid expression type
    >>> for dynamic_cast c:\Works\BaCCTester\Dev\Addins\Utils
    >>> \CommonDataManipulators\Sources\CommonDataFree.cpp 121
    >>> CommonDataManipulators
    >>> and the problematic line of code is this:
    >>> ...
    >>> FunctionResponse* pFunctionResponse =
    >>> ACE_dynamic_cast(FunctionResponse*, data);
    >>> ...
    >>> So it is logicaly that dynamic_cast does not work for
    >>> void-pointers since when I converted the pointer to void I
    >>> have given up all type information. But what makes me think
    >>> twice about the corectness of the previous sentence is that
    >>> this code compiles perfectly under Visual Studio 6. I would
    >>> like to know more about this issue so any help, references,
    >>> links and so are highly appriciated.

    >>
    >> The real question is what ACE_dynamic_cast is. I suspect that
    >> it's a macro, and probably expands differently depending on the
    >> compiler, but I really don't know.
    >>
    >> --
    >> James Kanze (GABI Software) email:
    >> Conseils en informatique orientée objet/
    >> Beratung in objektorientierter Datenverarbeitung
    >> 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

    >
    > Yes it is a macro
    > # define ACE_dynamic_cast(TYPE, EXPR) dynamic_cast<TYPE> (EXPR)
    > actualy it is a standard dynamic_cast and it is from the ACE
    > libraries


    And now, what is FunctionResponse and data. Could any of them be void?


    Bo Persson
    Bo Persson, Feb 26, 2008
    #7
  8. peter koch Guest

    On 26 Feb., 17:43, Puppet_Sock <> wrote:
    > On Feb 26, 8:18 am, "" <> wrote:
    >
    >
    >
    >
    >
    > > On Feb 26, 11:37 am, James Kanze <> wrote:

    >
    > > > On Feb 26, 10:33 am, "" <> wrote:

    >
    > > > > Ok now the problem is this.
    > > > > I have compiled some old code with Visual Studio 2008 (the
    > > > > code was originally writen in Visual Studio 6) and i have this
    > > > > error:
    > > > > Error   1       error C2681: 'void *' : invalid expression type for
    > > > > dynamic_cast    c:\Works\BaCCTester\Dev\Addins\Utils
    > > > > \CommonDataManipulators\Sources\CommonDataFree.cpp      121
    > > > > CommonDataManipulators
    > > > > and the problematic line of code is this:
    > > > > ...
    > > > > FunctionResponse* pFunctionResponse =
    > > > > ACE_dynamic_cast(FunctionResponse*, data);

    [snip]
    > > > The real question is what ACE_dynamic_cast is.  I suspect that
    > > > it's a macro, and probably expands differently depending on the
    > > > compiler, but I really don't know.

    >
    > > Yes it is a macro
    > > #   define ACE_dynamic_cast(TYPE, EXPR) dynamic_cast<TYPE> (EXPR)
    > > actualy it is a standard dynamic_cast and it is from the ACE libraries

    >
    > <InigoMontoyaVoice>You keep using that word. I do not think
    > it means what you think it means.</voice>
    >
    > In this news group, "standard" means part of the standard
    > C++ language, not part of a commercial library, no matter
    > how many people use it.


    But we found out that it really was a dynamic_cast (the errormessage
    itself did show that if you read carefull), and in that case the
    question definitely is standard, no matter if this is hidden inside
    some hideous macro.

    >
    > As to your original question:
    > - Did you read the help files for VS?
    >
    > Compiler Error C2681
    >
    > > A casting operator tried to convert from an invalid type.
    > > For example, if you use the dynamic_cast operator to
    > > convert an expression to a pointer type, the source
    > > expression must be a pointer.

    >
    > - Did you consider asking your question in a news group
    >   dealing with VS?
    >

    This question would only be appropriate in case the answer here
    indicated that VS has a nonstandard behaviour.

    [snip]

    /Peter
    peter koch, Feb 26, 2008
    #8
  9. wrote:
    > information. But what makes me think twice about the corectness of the
    > previous sentence is that this code compiles perfectly under Visual
    > Studio 6.


    VC6 reports the same error when 'dynamic_cast' is applied to a 'void*'
    expression.

    This means that it is absolutely impossible to figure out why it
    compiled in VC6 from the information you provided so far. It could be
    that in VC6 the expression was not 'void*' somehow. Or it could be that
    in VC6 the macro was actually mapped to 'static_cast'. Or something else.

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Feb 26, 2008
    #9
  10. peter koch Guest

    On 26 Feb., 10:33, "" <> wrote:
    > Ok now the problem is this.
    >
    > I have compiled some old code with Visual Studio 2008 (the code was
    > originally writen in Visual Studio 6) and i have this error:
    >
    > Error   1       error C2681: 'void *' : invalid expression type for
    > dynamic_cast    c:\Works\BaCCTester\Dev\Addins\Utils
    > \CommonDataManipulators\Sources\CommonDataFree.cpp      121
    > CommonDataManipulators
    >
    > and the problematic line of code is this:
    > ...
    > FunctionResponse* pFunctionResponse =
    > ACE_dynamic_cast(FunctionResponse*, data);
    > ...
    >
    > So it is logicaly that dynamic_cast does not work for void-pointers
    > since when I converted the pointer to void I have given up all type
    > information. But what makes me think twice about the corectness of the
    > previous sentence is that this code compiles perfectly under Visual
    > Studio 6. I would like to know more about this issue so any help,
    > references, links and so are highly appriciated.
    >


    If data is of type void* or FunctionResponse is of type void, the code
    above should not work.
    Visual Studio 6 probably got this wrong - it is a very old compiler.

    /Peter
    peter koch, Feb 26, 2008
    #10
  11. peter koch wrote:
    > If data is of type void* or FunctionResponse is of type void, the code
    > above should not work.


    I don't see why it shouldn't work when 'FunctionResponse' is really
    'void'. Conversion to 'void*' is a part of the standard 'dynamic_cast'
    functionality.

    > Visual Studio 6 probably got this wrong - it is a very old compiler.


    A quick experiment shows that its actually gets this right, meaning that
    the real root of the problem lies elsewhere.

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Feb 26, 2008
    #11
  12. Guest

    Thank you all very much.

    I just converted VC6 project that compiles ok into VC2008 and tried to
    compile. The error was what i got. However due to the complexity of
    the external library i have used (ACE), the macro might be redefined
    somewhere else. However this was not some blocking problem that i had,
    it just bothered me so it was just natural to ask :). Anyway at the
    end it all comes as I suspected, since as my memory serves me: void
    pointers do not have runtime type information and if you deliberately
    convert a pointer to void, you just given up its rtti.


    I am sorry if i have caused inconvinience by asking the question here,
    but i thought this would be a copiler issue, considering the compiler
    change from VC6 to VC2008.

    My Best Regards,
    and thank you all again

    --
    Tanev Nikola
    , Feb 27, 2008
    #12
  13. a écrit :
    > Thank you all very much.
    >
    > I just converted VC6 project that compiles ok into VC2008 and tried to
    > compile. The error was what i got. However due to the complexity of
    > the external library i have used (ACE), the macro might be redefined
    > somewhere else.


    I had a look into ACE (5.6.2) and this macro defined only once
    (ace/config-macros.h). I suspect it is a MSVC6 issue.

    Michael
    Michael DOUBEZ, Feb 27, 2008
    #13
    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. Amir
    Replies:
    3
    Views:
    583
  2. nc
    Replies:
    1
    Views:
    483
    nice.guy.nige
    Feb 3, 2005
  3. Replies:
    2
    Views:
    326
  4. =?Utf-8?B?TFc=?=
    Replies:
    8
    Views:
    399
    =?Utf-8?B?TFc=?=
    Apr 25, 2007
  5. LW
    Replies:
    1
    Views:
    164
    Alexey Smirnov
    May 2, 2007
Loading...

Share This Page