In C ++ 11, this is fully permitted if the two types are compatible with layouts, which is true for structures that are identical and have a standard layout. See this answer for more details .
You can also insert two structures in the same union in previous versions of C ++, which had some guarantees about the possibility of access to identical data elements ("common initial sequence" of data elements) in the same order for another structure types.
In this case, yes, a C-style cast is equivalent, but reinterpret_cast is probably more idiomatic.
John calsbeek
source share