Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!snorkelwacker.mit.edu!bloom-beacon!deccrl!news.crl.dec.com!pa.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!jituha!jit345!diamond From: diamond@jit345.swstokyo.dec.com (Norman Diamond) Newsgroups: comp.lang.c++ Subject: Re: the SUN way.. *&$^#%) Message-ID: <1991Jan2.053835.11860@jituha.enet.dec.com> Date: 2 Jan 91 05:38:35 GMT References: <1990Dec20.114821@roadster.bellcore.com> <3069@lupine.NCD.COM> <246@salt.bellcore.com> <3089@lupine.NCD.COM> Sender: news@jituha.enet.dec.com (USENET News System) Reply-To: diamond@jit345.enet.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 30 In article <3089@lupine.NCD.COM> rfg@NCD.COM (Ron Guilmette) writes: +In article <246@salt.bellcore.com> garnett@shera.UUCP (Michael Garnett) writes: ++Q: If is is "always legal to cast any pointer-to-T to a void*" then why ++ won't C++ accept compar(const T*, const T*)? (Assuming that my compiler ++ was correct in telling me that it wouldn't) Why does C++ allow ++ a call of the form 'free(T*)' when free has a parameter profile of ++ 'free(void*)'? I see no difference in these 2 cases. Both involve ++ accepting T* where a void* is wanted. + +You ask "why?" The answer is "Because those are the rules". There are +important differences in the two cases you cite. There is a real reason, which Mr. Guilmette almost hinted at. It is exactly true that any pointer-to-T can be CAST (converted) to a void*. On many machines, the representation is the same, so the cast is a no-op. However, on some machines, if a pointer-to-T is picked up and used bitwise, without conversion, as a void*, it might not point to the desired location. So if you have declarations: int a(char f(void*)); char g(float*)); then you want a diagnostic for this: x = a(g); Otherwise a will pass g something that g can't use. [Mr. Guilmette: Please kindly use your "r" or similar command to send me e-mail. I wish to see if news is working on this machine. Thank you.] Norman Diamond diamond@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it.