Re: warning C4238 : cast reference in void*



Eric wrote:
void foo(void* param)[...]

foo((void*) &szWord); //give C4238 warning : nonstandard extension
used : class rvalue used as lvalue

1. For your own sake, forget about the fact that C-style casts like the
above exist. I haven't found the need for one in over 1M lines of code and
you surely don't have such a case here.
Conversion from a typed pointer to a void pointer is implicitly done by the
compiler, so a cast isn't necessary. If you absolutely want, use a
static_cast, which is also the right cast to convert to a typed pointer
again.
2. Igor already mentioned it, this can't be the code you tried to compile,
please show the real code for an analysis of its problems.

Uli

.



Relevant Pages

  • Re: warning C4238 : cast reference in void*
    ... Conversion from a typed pointer to a void pointer is implicitly done by the ... so a cast isn't necessary. ... CString foo2(CString aString) ...
    (microsoft.public.vc.language)
  • Re: warning C4238 : cast reference in void*
    ... Conversion from a typed pointer to a void pointer is implicitly done by the ... so a cast isn't necessary. ... CString foo2(CString aString) ...
    (microsoft.public.vc.language)
  • Re: problem with memcpy and pointers/arrays confusion - again
    ... this second method is known as an explicit conversion, or cast. ... The cast, in effect, tells the compiler: ... the malloc function. ... function taking a size_t as a parameter and returning a void pointer (i.e. ...
    (comp.lang.c)
  • Re: about the array
    ... 3- If you cast to the wrong type by accident, ... are malloc and free. ... the compiler should issue a diagnostic - gcc ... unknown set of arguments, and return an int. ...
    (comp.lang.c)
  • Re: Can generics really produce strongly typed collections?
    ... The compiler won't detect the bug at compile time. ... will try to cast to B, ... The "foreach" statement specifically behaves in the way you ... interface, assuming one exists. ...
    (microsoft.public.dotnet.languages.csharp)