Consider the following C++ code that prints the alignment requirement for a double and the effective alignment of a structure member of type double:
#include <iostream>
struct S { short x; double y; };
int main() {
S s;
std::cout << __alignof(double) << ' ';
std::cout << (char*)&s.y - (char*)&s << std::endl;
}
I'm compiling this code with gcc on x86.
I was expecting this program to output 8 8, however it prints 8 4 instead. Why is that?