Why are structs not allowed in equality expressions in C? [duplicate]

一笑奈何 提交于 2019-12-04 06:02:09

Structures and unions cannot be compared for equality, even though assignment for these types is allowed. The gaps in structures and unions caused by alignment restrictions could contain arbitrary values, and compensating for this would impose an unacceptable overhead on the equality comparison or on all operations that modified structure and union types.

From "C: A Reference Manual". Even memcmp can fail when comparing structs, for the same reason (the compiler adding additional buffer space for alignment purposes). I guess they could implement member-by-member comparison; why they haven't is a different issue

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