automatic 16-byte alignment for structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux