Article View: comp.std.c++
Article #31Re: implicit pointer of pointer argument promotion legal C++?
From: Patrick Smith
Date: Tue, 03 Nov 1992 00:16
Date: Tue, 03 Nov 1992 00:16
37 lines
1799 bytes
1799 bytes
sdm@cs.brown.edu (Scott Meyers) writes: |In article <1992Oct31.213412.356@frumious.uucp> uunet.ca!frumious!pat writes: || In my understanding, one of the principles of C++ is that any construct || which has the potential to violate the type system is illegal unless || an explicit cast is used. So the explicit cast should be required in || the call to f() - not because the compiler knows there is a problem, || just because it _doesn't_ know there _isn't_. This is exactly why || you need an explicit cast to convert a pointer to base class to || pointer to derived class, but not to cast from derived to base. | |However, you don't need an explicit cast to go from a T* to a void*. Converting a T* to a void*, by itself, doesn't violate the type system, because a void* can point to anything. It's the conversion from a void* to a T* that might violate the type system, because the void* might not point to a T. Hence the explicit cast is required for this conversion. |Hence, given that this is legal, | | T *p; | void *q = p; | |is there a good reason why this isn't? | | void f(T*); | void (*pf)(void*) = f; Because it involves an implicit conversion of void* to T* (_not_ T* to void*). -- Patrick Smith uunet.ca!frumious!pat pat%frumious.uucp@uunet.ca
Technical Details
Message-ID:
<1992Nov3.001649.590@frumious.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!frumious!patReferences:
<1992Oct31.031431.6863@cs.brown.edu> <1992Oct31.213412.356@frumious.uucp> <1992Nov1.201547.4661@cs.brown.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!frumious!pat From: pat@frumious.uucp (Patrick Smith) Subject: Re: implicit pointer of pointer argument promotion legal C++? Message-ID: <1992Nov3.001649.590@frumious.uucp> Date: Tue, 3 Nov 1992 00:16:49 GMT Reply-To: uunet.ca!frumious!pat References: <1992Oct31.031431.6863@cs.brown.edu> <1992Oct31.213412.356@frumious.uucp> <1992Nov1.201547.4661@cs.brown.edu> Organization: None Lines: 37