I have Googled information on gcc’s __attribute__ ((aligned)) to learn more about how to use the attribute.
According to GNU “You may specify aligned and transparent_union attributes either in a typedef declaration or just past the closing curly brace of a complete enum, struct or union type definition and the packed attribute only past the closing brace of a definition.” In addition the document shows the following example:
struct S { short f[3]; } __attribute__ ((aligned (8)));
But I have found few examples with “typedef struct”. I found the following two:
typedef struct __attribute__ ((aligned)) { char a; int x; } foo;
typedef struct { char a; int x; } __attribute__ ((aligned)) foo;
Which is the preferred method: attribute after struct and before {, or attribute after } and before foo?
Do they both deliver the same result?
I would greatly appreciate any additional detail about the correct usage of __attribute__ ((aligned)) with a typedef:ed struct.
From the GCC doc: