Andreas F. Borchert wrote: > > foo *p = (foo *) m; /* CAST */ > ... > This line is not guaranteed to be ok due to § 6.3.2.3, (7): > > A pointer to an object type may be converted to a pointer to a different > object type. If the resulting pointer is not correctly aligned for the > referenced type, the behaviour is undefined. > > alignof(char) will be 1 and the alignment of foo will probably be 4, hence > there is no guarantee that the pointer value of p is properly aligned.
There is no guarantee, but the malloc() result has an alignment of at least 4 on all of today's platforms. [1] Bruno [1] see gnulib/lib/memalign.c and gnulib/m4/malloc-align.m4.