The aligned type attribute specifies a minimum alignment for the type. The aligned type attribute only increases the alignment of a struct or member, and does not decrease it.
Usage
You can use the packed and aligned attributes together on the same member to set the
alignment to a value. The value is less than the default value, but greater than one.
Example: Alignment of a packed 64-bit unsigned integer
Create alignment.c containing the following code:
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
struct foo {
uint8_t chA;
uint64_t dwB __attribute__((packed)) __attribute__((aligned(4)));
};
int main() {
printf(
"foo is size %d align %d, with chA at offset %d and dwB at offset %d\n",
sizeof(struct foo), _Alignof(struct foo), offsetof(struct foo, chA),
offsetof(struct foo, dwB));
return 0;
}
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.