[comp.lang.c++] Conversion to |void*| and back: LEGAL

chip@tct.uucp (Chip Salzenberg) (01/19/91)

[ 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