About the example below, in f1
, no alias occurs because p
(void*
) isn't accessible and p1
is the only pointer accessing memory.
However, there is a pointer aliasing between p1
(float*
) and p2
(int*
) which is outside f1
.
My question is that, is this alias illegal or not, that is, does the strict-aliasing rules apply across function calls ?
If this example is valid, what if the f1
is inlined ?
void f1(void *p)
{
auto* p1 = static_cast<float*>(p);
*p1 = 1.f;
}
int f2()
{
int x = 1;
auto* p2 = &x;
f1(&x);
*p2 = 1;
return *p2;
}