Topic: Conversion to |void*| and back: LEGAL
Author: chip@tct.uucp (Chip Salzenberg)
Date: 18 Jan 91 20:01:24 GMT Raw View
[ Standards-related discussion; followups redirected to comp.std.c++ ]
According to jimad@microsoft.UUCP (Jim ADCOCK):
>In article <278A3278.1241@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes:
>|If the text of the ARM does not explicitly support this point, then it
>|would seem there is an oversight in the text.
>
>Agreed that this is the most probable conclusion -- but, this conclusion
>doesn't clarify what the oversight was, nor how the ansification
>[isofication?] committee will fix it.
Okay, here's another line of argument:
ANSI C guarantees that any object pointer may be converted to |void *|
and back, and that the result will be equal to the original pointer.
The "Differences from ANSI C" section of the ARM (18.2) does not
rescind that guarantee. Therefore, it must still hold in C++.
Note that C++ pointers to user-defined object types cannot be excluded
from the above analysis. It is true that ANSI C has no "class" (:-)),
but we are discussing pointers, and |struct X *| and |class X *| are
the same type.
Thus, compatibility with ANSI C requires that this code output "yes":
class X { int x; } foo;
void *p = &foo;
if ((class X *)p == &foo)
cout << "yes\n";
--
Chip Salzenberg at Teltronics/TCT <chip@tct.uucp>, <uunet!pdn!tct!chip>
"If Usenet exists, then what is its mailing address?" -- me
"c/o The Daily Planet, Metropolis." -- Jeff Daiell
Author: rfg@NCD.COM (Ron Guilmette)
Date: 23 Jan 91 09:24:34 GMT Raw View
In article <27975414.50A8@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes:
>Okay, here's another line of argument:
>
>ANSI C guarantees that any object pointer may be converted to |void *|
>and back, and that the result will be equal to the original pointer.
>The "Differences from ANSI C" section of the ARM (18.2) does not
>rescind that guarantee. Therefore, it must still hold in C++.
That's a bad assumption. I have already noted other ommisions from
the list in 18.2. It is not a complete list.
--
// Ron Guilmette - C++ Entomologist
// Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg
// Motto: If it sticks, force it. If it breaks, it needed replacing anyway.