malloc()

Ray Butterworth rbutterworth at watmath.UUCP
Thu May 29 23:05:43 AEST 1986


> Ah, but if you have a function prototype such as:
> 	extern void free(void *);
> and then try to free a pointer to a struct, you are implicitly casting
> the struct pointer to a void *. Generating an error on this would
> make void * fairly useless.

But if I were king, free() wouldn't take a (void*).
Almost the only place (void*) would be used is by malloc().

There is a need for two special types of generic pointers:  one which
is guaranteed to be aligned and can be cast into any other pointer, and
one which has no such guarantee and can have any other pointer cast
into it.  (void*) clearly fits the former.  (char*) almost fits the
latter (perhaps a new (pointer) type should have been introduced).
X3J11 defeated the niceness of all this by extending their definition
of (void*) to fit both requirements.  I really don't understand why
they would do such a thing.  It gains nothing and loses a lot.



More information about the Comp.lang.c mailing list