Struct alignment and type reinterpretation
问题 Lets say I have two types A and B. Then I make this type struct Pair{ A a; B b; }; Now I have a function such as this. void function(Pair& pair); And lets assume that function will only ever use the a part of the pair. Then is it undefined behavior to use and call the function in this way? A a; function(reinterpret_cast<Pair&>(a)); I know that a compiler may insert padding bytes after a member but can it also do it before the first member? 回答1: I think it's defined behavior, assuming Pair is