Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Yet another bug (.NET 2002)

2 views
Skip to first unread message

Jacky Luk

unread,
Mar 1, 2006, 4:29:25 AM3/1/06
to
pOrdinalName =
(PIMAGE_IMPORT_BY_NAME)GetPtrFromRVA(reinterpret_cast<DWORD>(pINT->u1.AddressOfData),
pNTHeader, pImageBase);
----------------------------------------------------------------

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


Heinz Ozwirk

unread,
Mar 1, 2006, 11:15:33 AM3/1/06
to
"Jacky Luk" <j...@knight.com> schrieb im Newsbeitrag
news:%23n81hKR...@TK2MSFTNGP10.phx.gbl...

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


Igor Tandetnik

unread,
Mar 1, 2006, 11:36:45 AM3/1/06
to
Heinz Ozwirk <hozwir...@arcor.de> wrote:
> 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.

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


Heinz Ozwirk

unread,
Mar 1, 2006, 2:03:02 PM3/1/06
to
"Igor Tandetnik" <itand...@mvps.org> schrieb im Newsbeitrag
news:uWftu9UP...@TK2MSFTNGP10.phx.gbl...

> Heinz Ozwirk <hozwir...@arcor.de> wrote:
>> 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.
>
> Are you sure?

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


Jack

unread,
Mar 2, 2006, 3:33:07 AM3/2/06
to
Thanks both of you.
So what is the final conclusion?
Thanks
Jack

"Jacky Luk" <j...@knight.com> 撰寫於郵件新聞:%23n81hKR...@TK2MSFTNGP10.phx.gbl...

Jack

unread,
Mar 2, 2006, 3:37:42 AM3/2/06
to
And a simple remark
The <DWORD> was added based on someone else's suggestion on the USENet.
It was working since then (VC++ 6), when upgraded to .NET 2002, (I think the
newer compiler is more strict than Version 6), so refused to do so.
Jack

"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...

Heinz Ozwirk

unread,
Mar 2, 2006, 7:21:11 AM3/2/06
to
"Jack" <j...@knight.com> schrieb im Newsbeitrag
news:uahL2Pd...@TK2MSFTNGP10.phx.gbl...

> Thanks both of you.
> So what is the final conclusion?
> Thanks
> Jack

Don't cast.

Heinz

Alexander Grigoriev

unread,
Mar 3, 2006, 12:21:06 AM3/3/06
to
After reading the standard, looks like there is no reinterpret_cast from
integral/float rvalue to integral/float rvalue. This is static_cast domain.

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...

Tim Roberts

unread,
Mar 3, 2006, 2:31:30 AM3/3/06
to
"Jack" <j...@knight.com> wrote:
>
>Thanks both of you.
>So what is the final conclusion?

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.

Alexander Grigoriev

unread,
Mar 3, 2006, 11:25:18 PM3/3/06
to
The conclusion is that you cannot reinterpret_cast numeric type to numeric
type (but can do numeric lvalue to another numeric type reference).

"Tim Roberts" <ti...@probo.com> wrote in message
news:05sf02l781futqj2l...@4ax.com...

0 new messages