This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
automatic 16-byte alignment for structs
- From: Shmuel Hanoch <shmuel at infinitylabs dot co dot il>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 5 Mar 2017 20:02:26 +0200
- Subject: automatic 16-byte alignment for structs
- Authentication-results: sourceware.org; auth=none
Hi,
I noticed a strange behavior in gcc 5.4, in this simple code:
struct X { int x; };
int main()
{
X x1, x2, x3;
printf("%p %p %p\n", &x1, &x2, &x3);
}
I expected the distance between the addresses will be exactly the size
of the struct, which is 4 bytes on my platform (ubuntu 16.04, 64bit
system). Surprisingly, the distance is 16 bytes:
0x7fff4fb5cfd0 0x7fff4fb5cfe0 0x7fff4fb5cff0
If I replace the int in a char everything is normal (the distance is
just 1 byte). Also, in an array of structs the addresses are as
expected.
What is the source of this special behavior?
Thanks,
Shmuel Hanoch