Re: error C2664 with InterlockedExchangePointer
- From: Ulrich Eckhardt <eckhardt@xxxxxxxxxxxxxx>
- Date: Fri, 30 Sep 2005 09:13:21 +0200
Doug Harrison [MVP] wrote:
> On Thu, 29 Sep 2005 09:53:27 +0200, Ulrich Eckhardt
> <eckhardt@xxxxxxxxxxxxxx> wrote:
>>You can't convert between these two pointers, as they are unrelated. The
>>right thing to do is to to cast appropriately:
>>void** arg =
>>static_cast<void**>(static_cast<void*>(&mQ_waiting_for_write));
>>
>>Using reinterpret_cast will probably also work, although its effects are
>>implementation defined.
>
> The result of your two static_casts is equally unspecified.
Why?
> Practically speaking, there is no question whatsoever that:
>
> reinterpret_cast<void**>(&mQ_waiting_for_write)
>
> which is equivalent to:
>
> (void**) &mQ_waiting_for_write
The standard says that the results of reinterpret_cast are implementation
defined. The only guarantee given is that a reinterpret_cast back to the
initial type yields the same value, i.e. that it is reversible.
Other than that, consider the added safety that C++ style casts offer to C
style casts.
> will have the desired effect on a compiler for Windows. If it didn't, then
> pretty much all COM code would break. For that matter, I don't know of any
> system for which it won't work as desired.
A COM implementation might depend on compiler support anyway, so my intent
of portability is fooled anyway. Other than that, I have never seen a
system where a pointer is not 32 bits, but I know other systems are out
there and I don't take such chances.
Uli
.
- References:
- error C2664 with InterlockedExchangePointer
- From: Menny
- Re: error C2664 with InterlockedExchangePointer
- From: Ulrich Eckhardt
- Re: error C2664 with InterlockedExchangePointer
- From: Doug Harrison [MVP]
- error C2664 with InterlockedExchangePointer
- Prev by Date: Re: Run-Time Check Failure #0
- Next by Date: Re: using STL with unicode files
- Previous by thread: Re: error C2664 with InterlockedExchangePointer
- Next by thread: Different runtime behaviour of SetWaitableTimer() with periodical
- Index(es):
Relevant Pages
|