It doesn't matter what the array is contained in.
The standard does not even consider what surrounds something (it's that basic), but does support conversion to/from char
sequences.
To do this directly via reinterpret_cast
and assignment, you need to have the buffer correctly aligned.
An alternative is to use memcpy
, which doesn't care about alignment.
On a related issue, it's generally not a good idea to go down to the binary level. For example, a simple version change of the compiler might make a file of binary-serialized data inaccessible. A main driver for doing this anyway is raw performance considerations.