AMDG Ovanes Markarian wrote:
I know at least 2 books which describe this possibility and there is nothing stated about undefined behavior.
Unfortunately this is a very common mistake even among those who ought to know better.
I just double checked the ISO 2003 C++ Standards and did not find anything which disallows the presented approach. Can you point me to the paragraph in the Standard?
The usual aliasing rules apply with only one exception (listed in 9.5): [Note: one special guarantee is made in order to simplify the use of unions: If a POD-union contains several POD-structs that share a common initial sequence (9.2), and if an object of this POD-union type contains one of the POD-structs, it is permitted to inspect the common initial sequence of any of POD-struct members; see 9.2. ] In Christ, Steven Watanabe