void *

KW Heuer kwh at bentley.UUCP
Tue Apr 22 13:45:37 AEST 1986


In article <1883 at ucsfcgl.UUCP> ucsfcgl!arnold (Ken Arnold%CGL) writes:
>Purists will note that I really should say
>	ptr = (some_type *) malloc(10 * sizeof *ptr);
>But eventually malloc() will be of type "void *".

Okay, enlighten me.  When I first saw the idea of "void *" I thought it was
to be a name for the most restrictive pointer type ("ALIGN *" for those who
know the malloc source).  Then when I rechecked, I found that it was a new
name for the least restrictive pointer type, "char *".  Now you seem to say
that the cast operator is unnecessary in your example.  I'd like some more
detail about this beast.  Specifically, suppose we have the following:
	void  *v;
	char  *c;
	short *h;
	ALIGN *a;
Of the 12 nontrivial assignment statements, which ones will ANSI C accept
without a cast?  What will lint accept (with/without cast)?

Currently lint warns about things like h=c because it doesn't know whether c
is aligned properly for use as a short pointer.  Thus every nontrivial use of
malloc, even with the appropriate cast, generates a lint warning.  This is
why I thought that "void *" was going to mean "ALIGN *", which would be the
appropriate return value for malloc().  (Also more efficient, on word-based
machines.)

Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint



More information about the Comp.lang.c mailing list