Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: "Eugene Gershnik" <gershnik@xxxxxxxxxxx>
- Date: Sun, 17 Jul 2005 13:04:40 -0700
Slava M. Usov wrote:
> "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."
Ok that adds the "what is not mentioned is prohibited" restriction. (BTW
does the C standard say the same?).
> 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.
Ok. Though I doubt anything even marginally useful can be compiled in such
mode.
> [...]
>
>> If it works on certain platforms but not others the behavior should
>> be undefined.
>
> Indeed, why would anyone want to stick with a standard?
Indeed why in this particular case?
>>> 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]:
[...]
Well the standard is obviously out of sync with reality. Googling on this
issue reveals that even the standard comitteee members say so.
http://groups-beta.google.com/group/comp.lang.c++.moderated/msg/546501834bcbcc01?hl=en&
<quote>
....
This extension is so wide-spread as to be a
de facto standard, even though C explicitly forbids it, and X Open
System does nothing to even suggest that they differ from C here. One
could argue that a good compiler would not support it, but given the
ubiquity of the extension, I'm not sure; banning it would probably
break a lot of user code
....
</quote>
I still stand by what I wrote earlier. Either cast once and the cast will
work or don't cast at all. The double cast doesn't buy anything here.
--
Eugene
http://www.gershnik.com
.
- 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
- 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
- Re: bug in visual studio .net 2003 - breakpoints and memcpy
- From: Slava M. Usov
- 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