When is it valid to access a pointer to a “dead” object?

后端 未结 3 1251
野性不改
野性不改 2020-12-02 15:09

First, to clarify, I am not talking about dereferencing invalid pointers!

Consider the following two examples.

Example 1

3条回答
  •  佛祖请我去吃肉
    2020-12-02 15:44

    Example 2 is invalid. The analysis in your question is correct.

    Example 1 is valid. A structure type never holds a trap representation, even if one of its members does. This means that structure assignment, on a system where trap representations would cause problems, must be implemented as a bytewise copy, rather than a member-by-member copy.

    6.2.6 Representations of types

    6.2.6.1 General

    6 [...] The value of a structure or union object is never a t rap representation, even though the value of a member of the structure or union object may be a trap representation.

提交回复
热议问题