Following GCC __attribute__(packed ) will pack to byte boundary, aligned is used for which purpose :–
u8 rx_buf[14] __attribute__((aligned(8)));
struct S { short f[3]; } __attribute__ ((aligned (8)));
above array will be of 16 byte, am I right.
means sizeof(rx_buff) will be 16 byte .. i.e 2 byte alignment at end
The answer to your question is no. The
alignedattribute does not change the sizes of variables it is applied to, but the situation is slightly different for structure members. To quote the manual,and,
Note that the
alignedattribute may change the memory layout of structures, by inserting padding between members. Subsequently, the size of the structure will change. For instance:would lead to 15 bytes of padding after
awhereas the default alignment for the target architecture might have resulted in less. If you specified thepackedattribute for the structure and lost thealignedattributes the structure would have a size of 3 bytes.Here’s an illustration of how the memory layout of a structure might look like in each case.
struct twith no attributes and default alignment on 8-byte boundary:struct twhen a and b are aligned on 16-byte boundaries:struct twhen a and b have no alignment restrictions and t is packed: