I understand how padding works. I know what the alignment is. What is strange for me is, why the size of the struct with char fields only is not aligned to 4 bytes (padding at the end)? I suspect this is simply not guaranteed by the specification, so compiler does not do that. If that's the case, can I get the reference to such rule? I'm mostly interested in x86 and x86-64 architectures.
Example:
struct foo {
char field1;
char field2;
char field3;
} foo2;
int main(void)
{
printf("sizeof=%lu\n", sizeof foo2);
}
output: sizeof=3