Why 'void *' is useful

Kevin Martin kpmartin at watmath.UUCP
Mon Jul 9 09:01:26 AEST 1984


Pete Delaney asks...
>Why do we need void *, the 'universital pointer', the syntax is questionable?

I think that the word was 'universal'. Perhaps 'generic' might have been
a better word.
Basically, it is a reasonable thing to do with a construct which would
otherwise have to be made illegal.
The idea is to have a pointer which cannot be dereferenced without casting
it first. I find the syntax quite clear (In fact, this meaning for 'void *'
has already been implemented in our C compilers... it was suggested after
the compiler was found to be buggy in its treatment of casts into strange
types). It is a pointer that, if an attempt is made to indirect through it,
yields the illegal/unusable type 'void'.

A non-sensical use of 'void' would be to declare an object of type void
(not function-returning-void). e.g.
f() {
	void x;	/* Now what do I do with it? */
	...
}



More information about the Comp.lang.c mailing list