I have this memory that arrays of char
are the only safely punnable types in C++ according to the standard. That is, if you have a char*
pointer to the first element of an appropriately aligned and sized array of char
, it's safe to reinterpret_cast<T*>
that pointer, but would not be safe for e.g. uint8_t
according to the standard.
However, I can't find this anywhere in the current draft standard. Am I misremembering? Did this change for C++17? Can somebody quote the relevant parts of the standard?