What's the purpose of layout-compatible types?

前端 未结 2 661
独厮守ぢ
独厮守ぢ 2021-01-02 10:45

The standard defines when two types are layout-compatible. But, I don\'t see anywhere in the standard what the consequences are when two types are layout-compat

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 11:15

    The standard does define one specific case where layout compatibility matters: in unions. If two members are layout-compatible, and one of them is the active union member, then you may access that object through pointers/references to any layout-compatible member of that union. This is a consequence of the "common initial sequence" rule.

提交回复
热议问题