Is the strict aliasing rule incorrectly specified?

前端 未结 9 630
野的像风
野的像风 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:07

    The C11 standard (§6.5.2.3.9 EXAMPLE 3) has following example:

    The following is not a valid fragment (because the union type is not visible within function f):

     struct t1 { int m; };
     struct t2 { int m; };
     int f(struct t1 *p1, struct t2 *p2)
     {
           if (p1->m < 0)
                   p2->m = -p2->m;
           return p1->m;
     }
     int g()
     {
           union {
                   struct t1 s1;
                   struct t2 s2;
           } u;
           /* ... */
           return f(&u.s1, &u.s2);
     }
    

    But I can't find more clarification on this.

提交回复
热议问题