I have an array of floats (4 bytes per float) and I want to copy the data to an array of bytes (uint8_t) and treat it as bytes. Later I may want to copy the byte data back to a float array and treat it again as floats for various operations. Is this valid in c++? In other words is something like this where I treat the floats temporarily as bytes valid?
std::array<std::uint8_t, 40> b;
b.fill(0);
std::array<float,10> f;
f.fill(3.14);
std::memcpy(b.data(),f.data(),40);
std::array<float,10> f2;
f2.fill(0);
std::memcpy(f2.data(),b.data(),40);
for(std::size_t i=0;i<10;i++)
{
std::cout<<f2[i]<<std::endl; //now i want to access the float data
}