NFDream
NFDream

Reputation: 167

what‘s difference between __attribute__((packed,aligned(n))) and __attribute__((aligned(n)))?

Is there any difference between attribute((packed,aligned(n))) and attribute((aligned(n))) ?

Upvotes: 2

Views: 435

Answers (1)

Lily Ballard
Lily Ballard

Reputation: 185831

The aligned attribute specifies the minimum alignment the variable/field must have. The packed attribute requests that the variable/field should have the smallest possible alignment. So just using __attribute__((aligned(n)) sets the minimum alignment to n, but does not guarantee that it won't be larger. But using __attribute__((packed,aligned(n))) sets the alignment to precisely n.

Upvotes: 2

Related Questions