Using the new C ++ 11 alignment tools, I wanted to make sure that the set of temporary (stack) variables would be on the same cache line. My first naive attempt was as follows:
int main() { alignas(64) int a; // 0x7fffc58aac80, properly aligned at 64 int b; // 0x7fffc58aac7c int c; // 0x7fffc58aac78 return 0; }
Stupid me! Stack does not allocate variables this way, so a will be on a different cache line than b and c .
Does this mean that the only way to correctly align multiple variables is through the aggregate?
struct alignas(64) Abc { int x; int y; int z; }; int main() { Abc foo;
Compiler: Clang 3.2
source share