Help me cast this!

Doug Gwyn gwyn at brl-smoke.ARPA
Sat May 7 04:20:33 AEST 1988


In article <3802 at diku.dk> njk at diku.dk (Niels J|rgen Kruse) writes:
>... I gather that malloc has been redefined as void *malloc().
>Is a (void *) guaranteed to satisfy all alignment requirements?

No.  There are two distinct properties of the pointer returned by
malloc(): one is that it is a "generic" pointer, capable of being
safely converted to a pointer to any object type; the other is that
it is guaranteed to be properly aligned so that this conversion is
meaningful.  These two properties are NOT the same and should not
be bundled into a single language element.  The "super-aligned"
property is only true of pointers returned by malloc() and
therefore didn't seem to need a specific notion in the C language.
The "generic" property is essentially what ANSI C "void *" is
intended for.



More information about the Comp.lang.c mailing list