This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

automatic 16-byte alignment for structs


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]