This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] Fixes to bootstrap from a C++ compiler (part 1)
On Fri, Jun 25, 2004 at 09:27:55PM +0200, Gabriel Dos Reis wrote:
> Mark Mitchell:
>
> > Well, how do people feel about this? Is it good to rely on C's implicit
> > conversion between "void *" and other pointer types, or is OK to insert
> > casts necessary to satisfy the more restrictive C++ rule (where pointer
> > types implicitly convert to "void*" or not vice versa)?
>
> First of all, we should not be manipulating that many void* in the
> first place -- if we do, that means we have serious abstraction
> problem we should fix. Second, I believe we should insert the
> appropriate cast even if we know that it is unnecessary by
> C90 rules.
There's no abstraction involved. This is the return value of xmalloc.
The cast was necessary in K&R C, but not in C90, so we decided at the
time of the ISO C conversion that the result was cleaner without it.
> > (Personally, I've always viewed the implicit conversion from "void *" to
> > other pointer types in C a bug in the type system and I try to avoid
> > relying on it.)
>
> I'm on the same page as you. It is a hole in the type system
> the C committee introduced for I don't know exactly why. I see
> the implicit conversion void* -> T* a highly spurious programming
> style. I would definitely recommend against it.
In C++, you have new and delete, which have "magic" behavior in this
area. When you use other memory allocators, the collection of
otherwise unnecessary casts gets a bit old.
--
Daniel Jacobowitz