Re: warning C4238 : cast reference in void*




Ulrich Eckhardt wrote:
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

Thanks all, sorry I didn't give you the good code.

CString foo2(CString aString)
{
return aString;
}
void* foo(CString &aString)
{
return (void*)&foo2(aString); //give C4238 warning
}
int main()
{
CString aString;
void* ptr = foo(aString);
}

Eric

.



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 ... CString foo2(CString aString) ... CString aString; ...
    (microsoft.public.vc.language)
  • Re: Can I Trust Pointer Arithmetic In Re-Allocated Memory?
    ... You can't do pointer arithmetic on a void* value. ... qsort behaves in a manner consistent with its specification. ... actually works as advertised...but doesn't mean that the cast is ...
    (comp.lang.c)
  • Re: About casts (and pointers)
    ... > a cast). ... > the implementation's (void **) representation and length. ... Your sometype ** pointer is presumably pointing at ...
    (comp.lang.c)
  • Re: dynamic_cast does not work as specified
    ... then p is a pointer to an object of type SubThing. ... SubThing* via a C-style cast. ... virtual void ShowPURE; ... type-id must be a derived class of expression [note that the simple explanation could be ...
    (microsoft.public.vc.mfc)

Loading