Is the strict aliasing rule incorrectly specified?

前端 未结 9 682
野的像风
野的像风 2020-12-29 03:50

As previously established, a union of the form

union some_union {
    type_a member_a;
    type_b member_b;
    ...
};

with n memb

9条回答
  •  没有蜡笔的小新
    2020-12-29 04:16

    Under the definition of union members in §6.5.2.3:

    3 A postfix expression followed by the . operator and an identifier designates a member of a structure or union object. ...

    4 A postfix expression followed by the -> operator and an identifier designates a member of a structure or union object. ...

    See also §6.2.3 ¶1:

    • the members of structures or unions; each structure or union has a separate name space for its members (disambiguated by the type of the expression used to access the member via the . or -> operator);

    It is clear that footnote 95 refers to the access of a union member with the union in scope and using the . or -> operator.

    Since assignments and accesses to the bytes comprising the union are not made through union members but through pointers, your program does not invoke the aliasing rules of union members (including those clarified by footnote 95).

    Further, normal aliasing rules are violated since the effective type of the object after *f = 1.0 is float, but its stored value is accessed by an lvalue of type int (see §6.5 ¶7).

    Note: All references cite this C11 standard draft.

提交回复
热议问题