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?
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: Geoffrey Keating <geoffk at geoffk dot org>
- Cc: Daniel Berlin <dberlin at dberlin dot org>, gcc at gcc dot gnu dot org
- Date: Thu, 15 Jul 2004 19:35:10 +0000 (UTC)
- Subject: Re: Does malloc tell us anything about alignment modulo k?
- References: <3F979366-D66C-11D8-A090-000A95DA505C@dberlin.org><m2zn6183v6.fsf@greed.local>
On Thu, 15 Jul 2004, 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.
>
> 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.
The answer to C90 DR #075 says that being suitably aligned for any type
includes for types larger than the amount of memory allocated. As you
say, this probably isn't particularly useful.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)