Hello, here is a follow up thread about #1373391268524199966 . I open a new thread to refocus the discussion on a closely related topic
I'm considering this code (https://godbolt.org/z/9fd3zc7To):
struct Foo { int a; };
struct Bar { int a; };
void f(struct Bar *y, struct Foo *x) {
y->a = 7;
x->a = 5;
y->a += 4;
x->a *= 3;
}
int main(void)
{
void *z = malloc(128);
f(z, z);
struct Foo *x = z;
printf("a=%d\n", x->a);
}
I used to think f has UB because of strict aliasing rules. however, the article https://www.open-std.org/jtc1/sc22/WG14/www/docs/n3519.pdf makes me doubt
going through the example, it looks to me (with the perspective of the author, I mean) like that none of struct Foo nor struct Bar, will become the effective type for the allocated object (because none of the lvalue are actually of that type: they all have type int)
to inside of f, it looks to me that the object(s) referred to from x and y, are actually int effective types. Therefore, the code should actually not be UB ??????
I'm extremely confused: could someone with a clear interpretation of the spec help me walk through. the example, step by step, and tell me who has which effective type and why?