GCC #define for alignment
Andrew Haley
aph@redhat.com
Wed Dec 3 11:43:00 GMT 2008
Duane Ellis wrote:
> Hello,
>
> I have a problem in a memory allocator that acts like Malloc(), where I
> need to align the result value in the same form as malloc.
>
> I can easily hard code something :-( but I'd rather use some "well
> known" perhaps ANSI-C #define for the alignment value.
> It could be a GCC specific #define :-( but I'd rather it not be.
>
> Simply put, for portability reasons I'd rather not have a hard coded
> thing like this:
>
> // ensure proper machine alignment
> x = (x + 3) & (~3);
>
> Suggestions? Sure I could use sizeof(void *) also..
You want the largest possible alignment? That would be something
like
MAX (__alignof__ (double), __alignof__ (void *))
but you'd have to add a few more types to be sure.
Andrew.
More information about the Gcc-help
mailing list