This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Does malloc tell us anything about alignment modulo k?


Daniel Berlin <dberlin@dberlin.org> writes:

> I'm working on some trivial alignment analysis.
> Malloc'd memory is supposed to be "aligned suitably for any data type".
> Does this actually tell us anything about whether the result is
> aligned modulo k (IE aligned to a k byte boundary)?
> 
> Some OS'en seem to have stricter guarantees (Darwin guarantees the
> result of malloc is 16 byte aligned), i'm just trying to figure out
> whether the general case tells us anything.

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]