Aliasing Arrays through structs

后端 未结 3 964
暗喜
暗喜 2020-12-03 15:27

I\'m reading paragraph 7 of 6.5 in ISO/IEC 9899:TC2.

It condones lvalue access to an object through:

an aggregate or union type that includes

3条回答
  •  醉梦人生
    2020-12-03 15:43

    I think this text does not apply:

    an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union),

    sp->x has type unsigned int which is not an aggregate or union type.

    In your code there is no strict aliasing violation: it is OK to read unsigned int as unsigned int.

    The struct might have different alignment requirements to the array but other than that there is no problem.

    Accessing via "an aggregate or union type" would be:

    s t = *sp;
    

提交回复
热议问题