Memory layout of union of different sized member?

◇◆丶佛笑我妖孽 提交于 2019-11-30 08:22:48

It lies on the first 4 bytes. From the C99 standard §6.7.2.1/14:

The size of a union is sufficient to contain the largest of its members. The value of at most one of the members can be stored in a union object at any time. A pointer to a union object, suitably converted, points to each of its members (or if a member is a bit-field, then to the unit in which it resides), and vice versa.

This implies that the address of all members of a union is the same.

This really depends on ELF-ABI for that platform. See examples and figures give under section 3.1 in http://www.sco.com/developers/devspecs/abi386-4.pdf It shows that it need not start at low address, if there is padding due to alignment constraints.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!