Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: "Slava M. Usov" <stripit.slough@xxxxxxx>
- Date: Sun, 17 Jul 2005 21:00:23 +0200
"Eugene Gershnik" <gershnik@xxxxxxxxxxx> wrote in message
news:uDUo0HviFHA.1948@xxxxxxxxxxxxxxxxxxxxxxx
> Alexander Grigoriev wrote:
>> According to ANSI C and standard C++, there is no standard conversion
>> from a function pointer to void*, and vice versa. It's just not
>> listed among the possible conversions.
>
> Sounds like "undefined by omission" to me.
It's not. The C++ Standard says, in [expr.reinterpret.cast]: "Conversions
that can be performed explicitly using reinterpret_cast are listed below. No
other conversion can be performed explicitly using reinterpret_cast." In
[expr.cast], it also says "Any type conversion not mentioned below and not
explicitly defined by the user (12.3) is ill-formed."
So neither reinterpret_cast nor the explicit cast notation can be used to
convert pointer-to-function to pointer-to-object in standard C++.
VC7, in the standard conformance mode, rejects such conversions; it does
support them when language extensions are enabled.
[...]
> If it works on certain platforms but not others the behavior should be
> undefined.
Indeed, why would anyone want to stick with a standard?
>> A function pointer can be
>> converted to an integer of an appropriate size, though, which you may
>> (or may not) be able then convert to a void* (the size of the
>> necessary integer may be different from the required void* size).
>
> Now this is something I would definitely avoid doing. If a direct cast
> works it works. Otherwise the conversion is an error and the "double cast"
> doesn't help.
Nevertheless, this double conversion technique is the only one that the
standard recognizes [ibid]: "A pointer can be explicitly converted to any
integral type large enough to hold it. The mapping function is
implementation-defined [Note: it is intended to be unsurprising to those who
know the addressing structure of the underlying machine.] A value of
integral type or enumeration type can be explicitly converted to a pointer.
[...] mappings between pointers and integers are [...]
implementation-defined."
The "unsurprising" clause says all there is to say about the portability of
the technique; it is still "defined", albeit by the implementation.
S
.
- Follow-Ups:
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Slava M. Usov
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Pavel A.
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Eugene Gershnik
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- References:
- bug in visual studio .net 2003 - breakpoints and memcpy
- From: Gareth Haslip
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Alexander Grigoriev
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Eugene Gershnik
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Alexander Grigoriev
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Eugene Gershnik
- bug in visual studio .net 2003 - breakpoints and memcpy
- Prev by Date: Re: bug in visual studio .net 2003 - breakpoints and memcpy
- Next by Date: Re: bug in visual studio .net 2003 - breakpoints and memcpy
- Previous by thread: Re: bug in visual studio .net 2003 - breakpoints and memcpy
- Next by thread: Re: bug in visual studio .net 2003 - breakpoints and memcpy
- Index(es):
Relevant Pages
|
Loading