struct Intx4 {
int data[4];
};
Intx4 loadIntx4(void const *p) {
auto up alignas(1) = (int const *)p; // Does this line correct? (compiled ok in clang)
Intx4 r;
for (int i = 0; i < 4; i++) r.data[i] = up[i];
return r;
}
I also tried the followings, they all failed to compile in clang:
int const *up alignas(1) = (int const *)p;
auto up = (int const alignas(1) *)p;
To read an unaligned integer:
There is no unaligned integer type in C++, so you have to make do with
void*
.