Suppose we take a very large array of unsigned char s.
std::array<uint8_t, 100500> blob;
(Note: it is already aligned, the question is not about alignment). Then we take it as uint64_t[] and try to access it:
const auto ptr = reinterpret_cast<const uint64_t*>(blob.data()); std::cout << ptr[7] << std::endl;
Going to uint64_t and then reading from it looks suspicious, as it does for me.
But UBsan, -Wstrict-aliasing does not start about it. Google uses this method in FlatBuffers . In addition, Cap'n'Proto uses this.
Is this behavior undefined?
source share