I'm testing a small code fragment and I'm surprised the same representation of 4 bytes as put into std::array and std::tuple yield different in-memory layouts
#include <iostream>
#include <tuple>
#include <array>
struct XYZW {
uint32_t x;
uint32_t y;
//std::array<uint8_t,4> z;
std::tuple<uint8_t, uint8_t, uint8_t, uint8_t> z;
uint32_t w;
};
int main() {
XYZW i;
i.z = {255, 0, 0, 0};
uint32_t z = (*reinterpret_cast<uint32_t*>(&i.z));
std::cout << z << " \n";
}
For tuple the output is: 4278190080, while for the array it is: 255.
Is this expected?