Medium
Four alignas(64) counters in a row
On a typical x86-64 target with 64-byte cache lines, what does this program print?
main.cpp
#include <atomic>
#include <iostream>
struct alignas(64) PaddedCounter { // (1) force cache-line alignment + size
std::atomic<long> value{0};
};
PaddedCounter counters[4]; // (2) each counter gets its own line
int main() {
std::cout << sizeof(PaddedCounter) << " "
<< sizeof(counters) << " "
<< (reinterpret_cast<char*>(&counters[1])
- reinterpret_cast<char*>(&counters[0]))
<< std::endl;
}66 of 117 in C++