Do you have to cast void pointers when dereferencing them?

Norman Diamond diamond at csl.sony.JUNET
Fri Dec 23 15:35:33 AEST 1988


In article <773 at auspex.UUCP>, guy at auspex.UUCP (Guy Harris) writes:

> ... some
> compilers may object to converting a "char *" to an "int *" without a
> cast (not because they don't know how to do it, but because it's not
> *required* to be permitted by the dpANS, and because it could be
> difficult or impossible in some implementations).
  ^^^^^^^^^    ^^^^^^^^^^

I've got bad news for those compilers.  They may not object to
converting a "void *" to an "int *" and that "void *" must have the
same representation as a "char *".  So if it's difficult, they have
to do difficult things.  If it's impossible, then they don't have C
and they never had malloc().

Sure, any code that ever used malloc() before the invention of (void *)
was already broken, right?  So ANSI isn't really breaking working code.
But to be sensible, compilers really ought to allow conversion between
(char *) and other pointer types.
-- 
Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp at relay.cs.net)
  The above opinions are my own.   |  Why are programmers criticized for
  If they're also your opinions,   |  re-inventing the wheel, when car
  you're infringing my copyright.  |  manufacturers are praised for it?



More information about the Comp.lang.c mailing list