Path: utzoo!censor!dybbuk!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!uunet!pdn!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.lang.c++ Subject: Casting T* -> void* -> T*, redux Keywords: Sun, C++ Message-ID: <27AB038D.E25@tct.uucp> Date: 2 Feb 91 18:23:09 GMT Article-I.D.: tct.27AB038D.E25 References: <1991Jan9.161633.21922@clear.com> <1991Jan21.022720.20707@cbnewsk.att.com> <70271@microsoft.UUCP> Organization: Teltronics/TCT, Sarasota, FL Lines: 25 According to jimad@microsoft.UUCP (Jim ADCOCK): >I see nothing in ARM that gives one permission to explicitly cast >back from a void* back to the original object* type. Nor do I, lamentably. >What C++ does permit is casting back from a pointer to a smaller object. >I don't see anywhere ARM defines that the effective size of a void object... Aha! This is yet another reason why such a cast-back must be supported by any minimally sane C++ implementation. To wit: For compatibility with ANSI C, a C++ implementation must represent |char*| and |void*| identically -- that is, if you call a C function that expects a |void*| and give it a |char*|, or vice versa, it has to work correctly -- even if the prototype has it wrong. So given (1) the |T*| -> |char*| -> |T*| conversion must work, and (2) |char*| and |void*| must have identical representations, thus we can conclude that |T*| -> |void*| -> |T*| will certainly work in any C++ implementation that isn't terminally stupid. -- Chip Salzenberg at Teltronics/TCT , "I want to mention that my opinions whether real or not are MY opinions." -- the inevitable William "Billy" Steinmetz