S
Spoon
Hello everyone,
I had expected my C++ compiler to add padding within classes and structs
to align fields to their "natural" boundary. This seems not to be true.
$ cat align.cxx
#include <cstdio>
struct foo
{
virtual void f() const { }
long long x;
};
int main()
{
foo bar;
printf("%p %p\n", (void *)&bar, (void *)&bar.x);
return 0;
}
$ ./a.out
0xbfd9da00 0xbfd9da04
On my platform (x86 Linux g++) long long is 64-bits wide.
(I suppose the first 4 bytes store the v-pointer.)
Why didn't the compiler add padding to align x to a 64-bit boundary?
Regards.
I had expected my C++ compiler to add padding within classes and structs
to align fields to their "natural" boundary. This seems not to be true.
$ cat align.cxx
#include <cstdio>
struct foo
{
virtual void f() const { }
long long x;
};
int main()
{
foo bar;
printf("%p %p\n", (void *)&bar, (void *)&bar.x);
return 0;
}
$ ./a.out
0xbfd9da00 0xbfd9da04
On my platform (x86 Linux g++) long long is 64-bits wide.
(I suppose the first 4 bytes store the v-pointer.)
Why didn't the compiler add padding to align x to a 64-bit boundary?
Regards.