void * (was: Is "void f(int i) { return (void)i; }" legal?)

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Apr 14 12:07:15 AEST 1990


In article <1841 at ambush.dk> andrew at ambush.dk (Leif Andrew Rump) writes:
>it is a bit puzzling at first to see that void * is legal but I sure
>rather want that than char * as it was in malloc and other in the past

The trick is to realize that there are no void objects; void denotes
an incomplete type that cannot be completed!  Thus when a pointer of
type void * points to some object, the type of the pointed-to object
cannot be void but must be determined in some other way.  The standard
library routines have void * parameters when they are expected to be
used to operate with a variety of different actual object types.
Since objects are made up of bytes, we COULD have continued to use
char * to point at arbitrary objects, but void * permits stronger type
checking, and that was considered to be a Good Thing.



More information about the Comp.std.c mailing list