c:\Documents and Settings\abc\abc\SRC\PEload.cpp(169): error C2440:
'reinterpret_cast' : cannot convert from 'DWORD' to 'DWORD'
Thanks for any inspections
Jack
There is a simple solution to that problem -- don't cast. Or at least don't
use reinterpret_cast. But this is not a bug, it is required by the standard.
There you can find quite a short list of conversions, reinterpret_cast can
be used for, and converting an integral value to its own type is not among
them.
Heinz
Are you sure?
5.2.10/2 The reinterpret_cast operator shall not cast away constness.
[Note: see 5.2.11 for the definition of ''casting away constness''.
Subject to the restrictions in this section, an expression may be *cast
to its own type* using a reinterpret_cast operator. ]
Emphasis mine. But Comeau compiler agrees with you and flags
reinterpret_cast to the same type as an error. I wonder what this note
is trying to say.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Not really, but Comeau also dislikes it, as we both tried.
> 5.2.10/2 The reinterpret_cast operator shall not cast away constness.
> [Note: see 5.2.11 for the definition of ''casting away constness''.
> Subject to the restrictions in this section, an expression may be *cast to
> its own type* using a reinterpret_cast operator. ]
>
> Emphasis mine. But Comeau compiler agrees with you and flags
> reinterpret_cast to the same type as an error. I wonder what this note is
> trying to say.
5.2.10/2 The reinterpret_cast operator shall not cast away constness.
[Note: see 5.2.11 for the definition of ''casting away constness''.
*Subject to the restrictions in this section*, an expression may be cast to
its own type using a reinterpret_cast operator. ]
I don't know either, but I can emphasis an other part of that quote. But
there are other ways (I don't like to call them better ones) to cast an
expression to its own type, like static_cast. reinterpret_cast is the last
resort to do nasty things that C style casts could do, but static_cast
cannot. And after all, such little differences force stupid programmers like
me and you to use our brains. And it teaches us not to put all the blame on
the poor compiler, not even on VC ;-)
Heinz
"Jacky Luk" <j...@knight.com> 撰寫於郵件新聞:%23n81hKR...@TK2MSFTNGP10.phx.gbl...
"Jack" <j...@knight.com> 撰寫於郵件新聞:uahL2Pd...@TK2MSFTNGP10.phx.gbl...
> Thanks both of you.
> So what is the final conclusion?
> Thanks
> Jack
>
> "Jacky Luk" <j...@knight.com> ???gco?l¥o·s?D:%23n81hKR...@TK2MSFTNGP10.phx.gbl...
Don't cast.
Heinz
The cast in question would succeed though, if the target type was DWORD &
(possibly const, too).
"Heinz Ozwirk" <hozwir...@arcor.de> wrote in message
news:4405efe6$0$22079$9b4e...@newsread2.arcor-online.net...
The final conclusion is that the expression is already a DWORD, and it is
not valid to use reinterpret_cast to convert something to its own type.
So, remove the cast.
--
- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
"Tim Roberts" <ti...@probo.com> wrote in message
news:05sf02l781futqj2l...@4ax.com...