I'm curious about the alignment of uint32_t types on 64-bit platforms. The spec says that uint32_t should be exactly the given bitwidth, which indeed it seems to be:
> printf("sizeof(uint32_t): %zd\n", sizeof(uint32_t));
sizeof(uint32_t): 4
But then I have a struct:
typedef struct A {
uint32_t a;
uint32_t b;
} A;
But, surprisingly:
> printf("sizeof(A): %zd\n", sizeof(A));
sizeof(A): 16
Is uint32_t being 8-byte aligned for some reason? Is it really a 8-byte type underneath?
uint32_t
must be less than or equal tosizeof(uint32_t)
. Because of the requirement that there be no padding inuintN_t
types,sizeof(uint32_t) * CHAR_BIT == 32
. Anything else is non-conforming to C99. However, the alignment of yourstruct A
is permitted by C99 to be bigger the biggest alignment of any member. – Discombobulateb
to be 8-aligned. – Discombobulate