This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Does malloc tell us anything about alignment modulo k?
On Jul 15, 2004, at 15:30, Geoffrey Keating wrote:
In general, if malloc(x) is called, and a type exists on the target
whose size is no more than x and which has alignment y, then the
result of the malloc also has alignment at least y.
Though this is true in theory, it's not in practice, especially
when taking into account vector types that require large alignment.
On many x86 systems, malloc (16) will not be aligned on a 16-byte
boundary.
So, for instance, you can deduce that malloc(16) on Darwin is 16-byte
aligned. You can't deduce the same for malloc(2), but it's not clear
how knowing that's alignment would be useful anyway.
It's easy to address anyway, by adjusting the argument to be at least
the alignment. This is always OK.
-Geert