malloc()

Ron Natalie <ron> ron at brl-sem.ARPA
Sun Jun 1 17:15:03 AEST 1986


In article <113 at watmath.UUCP>, rbutterworth at watmath.UUCP (Ray Butterworth) writes:

> 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.

Eh?  "void *" is a pointer that is big enough to hold any other pointer.
It makes no attempt at alignment.  Nowhere in C is there any guarantees
on alignment.  You assign an unaligned char into an int pointer on some
machines it will work, some it won't be aligned right, and some will
generate bizarre pointers as a result.  It is a feature of MALLOC that
it never puts anything into that void* it returns that isn't aligned,
but that is extremely implentation dependant.

-Ron



More information about the Comp.lang.c mailing list